Skip to content

Specifying configuration( -c config/pytest.ini) from non-project-root directory leads to local fixtures ignore #13246

Open
@andrewshkovskii

Description

@andrewshkovskii

When pytest is run with a configuration file that is not in the project root directory, the rootdir becomes the pytest.ini directory(in my case, with pytest -c config/pytest.ini, the rootdir becomes config/ and fixture collection and caching(probably) is broken. Fixtures from different directory level conftests but with the same name are re-used wrongly(See Makefile 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 2

This will make test2 fail since fixture value returns 1, ignoring local fixture from the local conftest:

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
Package   Version
--------- -------
iniconfig 2.0.0
packaging 24.2
pluggy    1.5.0
pytest    8.3.4
  • pytest>=8.3 and Ubuntu 24.04.2 LTS
  • There are Makefile commands to run to check that the bug exists. make bug-showcase runs the tests, fails and shows the bug. make no-bug-showcase should not fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: configrelated to config handling, argument parsing and config filetype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions