Last active
December 1, 2020 16:18
-
-
Save hectorcanto/5469b9283097e75b309ccbc30d44ac50 to your computer and use it in GitHub Desktop.
Automatic markers
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
def pytest_collection_modifyitems(items): | |
""" | |
Add marker to all tests in the conftest folder tree. | |
You need to organize your tests in folders for it to work. | |
Usage: `pytest -m $marker_expression` | |
Example: `pytest -m unit1 | |
Reference: https://docs.pytest.org/en/stable/reference.html?highlight=collection_modi#pytest.hookspec.pytest_collection_modifyitems | |
""" | |
for item in items: | |
if "/integration/" in str(item.module): | |
item.add_marker("integration") | |
elif "/unit/" in str(item.module): | |
item.add_marker("unit") | |
elif "/smoke/" in str(item.module): | |
item.add_marker("smoke") |
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
[pytest] | |
markers = | |
current: tests you are currently testing | |
unit: unit tests, no dependencies | |
smoke: launch these ones first | |
integration: has dependencies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment