It is possible to only run tests marked by a certain marker by using the -m
argument when calling pytest.
e.g. pytest -m testsubset_a
.
I wonder... Is it also possible to enable one of these markers from inside the code? e.g. somewhere during pytest_collection_modifyitems()
?
The reason why I'm asking is because I'm working on a test-harnass that will use pytest markers to enable a specific subset of tests, but did not do so in the past. Since we want to be backwards compatible, I want to enable a default subset (marker) when no -m
argument was given.
You can access the markers passed to
-m
from inside the code quite easily withconfig.option.markerexpr
.So... defaulting when no option was passed is as easy as