Skip to content

Instantly share code, notes, and snippets.

@hectorcanto
Last active December 1, 2020 16:18
Show Gist options
  • Save hectorcanto/5469b9283097e75b309ccbc30d44ac50 to your computer and use it in GitHub Desktop.
Save hectorcanto/5469b9283097e75b309ccbc30d44ac50 to your computer and use it in GitHub Desktop.
Automatic markers
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")
[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