Given this layout:
.
├── src
│ ├── conftest.py
│ └── mycode
│ ├── __init__.py
│ └── main.py
└── tests
├── conftest.py
├── __init__.py
└── test_mycode.py
4 directories, 6 files
If I define min311
in tests/conftest.py
, then in test_mycode.py
I can write:
from tests.conftest import min311
@min311
def test_something():
...
This assumes that we are running pytest
from the top-level directory.
This also works for the simpler layout:
.
├── conftest.py
├── mycode
│ ├── __init__.py
│ └── main.py
└── tests
├── conftest.py
├── __init__.py
└── test_mycode.py
If you don't want to import from conftest
directly, just move the decorator definition somewhere more palatable. I've seen a number of projects that include something like a test_helpers
module in their code:
.
├── conftest.py
├── mycode
│ ├── __init__.py
│ ├── main.py
│ └── test_helpers.py
└── tests
├── conftest.py
└── test_mycode.py
Then you can:
from mycode.test_helpers import min311