pytest-dev / pytest-dev/pytest
9.1: interleaving a file arg with a sibling package's file args orphans that package's conftest fixtures (fixture '…' not found)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Title: 9.1: interleaving a file arg with a sibling package's file args orphans that package's conftest fixtures (fixture '…' not found)
Environment: pytest 9.1.1, CPython 3.12, Windows 11. (Believed introduced by the pytest-9 conftest/fixture rework that binds fixtures onto the collector node object and matches by node identity; the pre-9 string-baseid matching would have masked it.)
What happens
When the command line lists a test file that sits directly under a directory between files that live under a subpackage of that same directory, the subpackage's conftest.py fixtures become invisible for the run — every test needing one errors out with fixture '<name>' not found, even though the fixture is defined and the same files pass in isolation or when the args are reordered.
Minimal reproducer
Layout:
tests/
conftest.py # (empty is fine)
test_top.py # a file directly under tests/, no special fixtures
pkg/
conftest.py # defines: @pytest.fixture\n def widget(): return 1
test_a.py # def test_a(widget): assert widget == 1
test_b.py # def test_b(widget): assert widget == 1
# FAILS — errors: fixture 'widget' not found (for test_b, the pkg arg AFTER test_top.py)
$ pytest tests/pkg/test_a.py tests/test_top.py tests/pkg/test_b.py
# PASSES — same files, the top-level file listed FIRST
$ pytest tests/test_top.py tests/pkg/test_a.py tests/pkg/test_b.py
# PASSES — directory arg
$ pytest tests/
Expected
Interleaving a directly-named file with a sibling package's file args should not change fixture resolution; the package's conftest.py fixtures should resolve regardless of arg order (as they do for a directory arg).
Workarounds (for other users hitting this)
- Pass directories (
pytest tests/), or - List any file directly under a package before that package's subdirectory files.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by creating the tests/pkg and tests/test_top.py layout from the reproducer and run the two file-order commands under pytest 9.1.1. Then inspect the pytest 9 conftest/fixture rework, especially collector-node identity matching, and compare collection for interleaved file arguments with directory arguments. Done means the package conftest fixture resolves regardless of argument order and the reproducer passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100