I would like to use a "helper" decorator in multiple pytest test files:
min311 = pytest.mark.skipif(sys.version_info < (3,11), reason="You need at least Python v3.11 to run this test")
...
@min311
def test_...
Which is the best place for min311? It is not imported automatically from conftest.py.
Given this layout:
If I define
min311intests/conftest.py, then intest_mycode.pyI can write:This assumes that we are running
pytestfrom the top-level directory.This also works for the simpler layout:
If you don't want to import from
conftestdirectly, just move the decorator definition somewhere more palatable. I've seen a number of projects that include something like atest_helpersmodule in their code:Then you can: