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)

Open
#14,997 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.