Pytest 8 broke sorting for package-scoped fixtures #12328
Labels
topic: collection
related to the collection phase
topic: fixtures
anything involving fixtures directly or indirectly
type: bug
problem that needs to be addressed
type: regression
indicates a problem that was introduced in a release which was working previously
Pytest 8 has a regression where the test reordering no longer favours reuse of package-scoped fixtures. If a parametrised package-scoped fixture is used in multiple modules within the same package, then instead of running the whole package with one fixture instantiation before switching to the next, it runs a module at a time, causing the fixture to be torn down and recreated each time.
MWE
conftest.py
:pkg/__init__.py
: emptypkg/test_things1.py
:pkg/test_things2.py
:Output of
pytest --setup-plan
from pytest 8.2.0:Whereas pytest 7.4.4 produces:
If the fixture is not parametric (or has only one parameter), it does correctly re-use the fixture across the whole package, so the issue seems to be related to sorting rather than re-use.
Changing the scope to
session
gives sensible behaviour, so it seems to be specific to package scope.System information
pip list:
OS: Ubuntu 24.04
pip list
from the virtual environment you are usingThe text was updated successfully, but these errors were encountered: