You can attach the common marker programmatically, e.g. in the pytest_collection_modifyitems
hookimpl:
import pytest
def pytest_collection_modifyitems(items):
for item in items:
item.add_marker(pytest.mark.foo)
If only tests from selected subtrees should be marked, extend the above impl with a test module file check, e.g.
import pathlib
import pytest
# assuming all tests are stored in a `tests` directory
dirs = (pathlib.Path("tests/foo"), pathlib.Path("tests/bar/baz"))
def pytest_collection_modifyitems(config, items):
for item in items:
testmod = pathlib.Path(item.fspath)
if any(config.rootdir / dir in testmod.parents for dir in dirs):
item.add_marker(pytest.mark.foo)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…