Specifying configuration( -c config/pytest.ini
) from non-project-root directory leads to local fixtures ignore
#13246
Labels
topic: config
related to config handling, argument parsing and config file
type: regression
indicates a problem that was introduced in a release which was working previously
When
pytest
is run with a configuration file that is not in the project root directory, therootdir
becomes thepytest.ini
directory(in my case, withpytest -c config/pytest.ini,
therootdir
becomesconfig/
and fixture collection and caching(probably) is broken. Fixtures from different directory levelconftests
but with the same name are re-used wrongly(SeeMakefile
https://github.com/andrewshkovskii/pytest-fixtures-collection-bug/blob/master/Makefile for examples). The fixture collected first will be re-used in other tests, ignoring the local fixture with the same name.You can find the bug reproduction in this repo https://github.com/andrewshkovskii/pytest-fixtures-collection-bug
Example:
tests
--- tests1
---- test1.py checks that fixture
value
==1
---- conftest.py
----- fixture
value
returns 1--- tests2
---- test2.py checks that fixture
value
==2
---- conftest.py
----- fixture
value
returns 2This will make
test2
fail since fixturevalue
returns1
, ignoring local fixture from the localconftest
:pytest -c config/pytest.ini -vvv tests/tests2/test2.py::test2 tests/tests1/test1.py::test1
This works as expected:
pytest -c config/pytest.ini --rootdir=. -vvv tests/tests2/test2.py::test2 tests/tests1/test1.py::test1
uv pip list
pytest>=8.3
andUbuntu 24.04.2 LTS
make bug-showcase
runs the tests, fails and shows the bug.make no-bug-showcase
should not failThe text was updated successfully, but these errors were encountered: