-
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.
* tests: add pytest flags --------- Co-authored-by: Leonid Kuligin <[email protected]>
- Loading branch information
Showing
11 changed files
with
121 additions
and
15 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,64 @@ | ||
""" | ||
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 pytest CLI. | ||
Args: | ||
parser: The pytest parser object. | ||
Returns: | ||
""" | ||
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 pytest custom configuration. | ||
Args: | ||
config: The pytest config object. | ||
Returns: | ||
""" | ||
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. | ||
Args: | ||
config: The pytest config object. | ||
items: The list of tests to be executed. | ||
Returns: | ||
""" | ||
for item in items: | ||
keywords = list(set(item.keywords).intersection(_PYTEST_FLAGS)) | ||
if keywords and not any((config.getoption(f"--{kw}") for kw in keywords)): | ||
skip = pytest.mark.skip(reason=f"need --{keywords[0]} option to run") | ||
item.add_marker(skip) |
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.