quaint-telephone-89068
12/09/2022, 5:14 PMproject1
tests/
conftest.py (with project1 specific fixtures)
test_module.py
project2
tests/
conftest.py (with project2 specific fixtures)
test_module.py
conftest.py (with generic fixtures)
when running tests in project1/tests directory, pytest visits all ancestor directories until reaching the root collecting all conftest.py so that fixtures are available.
From the docs:
Pants will also infer dependencies on any confest.py files in the current directory and any ancestor directories, which mirrors how Pytest behaves.This means that when making changes to the root
conftest.py, all tests will need to be run because every test depends on that root conftest.py. It's possible to disable this behavior:
You can turn off this feature by setting conftests = false in the [python-infer] scope.However, it seems fair that all subprojects may want to use a generic fixture from the root
conftest.py. But this negatively affects the dependency management within tests as all tests (some of them maybe slow!) will need to be run every time someone touches the root conftest.py (since you don't know whether the fixtures a test uses are actually modified).
Importing individual fixtures (so that you would split the root conftest.py into individual modules) seems to be discouraged: pytest docs suggest you define all your fixtures within one single conftest.py file. There is an explicit import approach, but I am not sure what are the cons of this approach?
# tests/conftest.py
import pytest
from fixtures.add import add
I see usage of
pytest_plugins = (
"fixtures.fixture_1",
"fixtures.fixture_2",
)
in various repositories, but this doesn't work well with Pants dependency inference (as there are no import statements).
What kind of approach have you decided to go with?
pantsbuild/pants