-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Tests configuration to be executed before tests execution. | ||
""" | ||
|
||
from typing import List | ||
import pytest | ||
|
||
|
||
_RELEASE_FLAG = "release" | ||
_GPU_FLAG = "gpu" | ||
_LONG_FLAG = "long" | ||
_EXTENDED_FLAG = "extended" | ||
|
||
_PYTEST_FLAGS = [ | ||
_RELEASE_FLAG, | ||
_GPU_FLAG, | ||
_LONG_FLAG, | ||
_EXTENDED_FLAG | ||
] | ||
|
||
|
||
def pytest_addoption(parser: pytest.Parser) -> None: | ||
""" | ||
Add flags accepted by our pytest CLI, | ||
:param parser: The pytest parser object. | ||
:return: | ||
""" | ||
for flag in _PYTEST_FLAGS: | ||
parser.addoption(f"--{flag}", action="store_true", default=False, help=f"run {flag} tests") | ||
|
||
|
||
def pytest_configure(config: pytest.Config) -> None: | ||
""" | ||
Add our custom configuration, | ||
:param config: The pytest config object. | ||
:return: | ||
""" | ||
for flag in _PYTEST_FLAGS: | ||
config.addinivalue_line("markers", f"{flag}: mark test to run as {flag} only test") | ||
|
||
|
||
def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item]) -> None: | ||
""" | ||
Skip tests with a marker from our list that were not explicitly invoked. | ||
:param config: The pytest config object. | ||
:param items: The list of tests to be executed. | ||
:return: | ||
""" | ||
for item in items: | ||
keywords = list(set(item.keywords).intersection(_PYTEST_FLAGS)) | ||
if keywords and not any((config.getoption(f"--{keyword}") for keyword in keywords)): | ||
item.add_marker(pytest.mark.skip(reason=f"need --{keywords[0]} option to run")) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.