Skip to content

[Rejected ai slop]fix: register conftest fixtures by nodeid for Directory nodes - #14965

Closed
dajiaohuang wants to merge 1 commit into
pytest-dev:mainfrom
dajiaohuang:fix/14964-conftest-fixtures
Closed

[Rejected ai slop]fix: register conftest fixtures by nodeid for Directory nodes#14965
dajiaohuang wants to merge 1 commit into
pytest-dev:mainfrom
dajiaohuang:fix/14964-conftest-fixtures

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

Fixes #14964

Conftest fixtures are silently missing for files collected after a file argument from an ancestor directory. This is a regression in pytest 9.1.0+ from #14004.

Root Cause

Since #14004, conftest fixtures are parsed and registered against the specific Directory NODE that collects the conftest's directory. When a file is passed directly (not via directory collection), pytest may re-collect the ancestor directory with fresh child node objects. The new node never receives the conftest's fixtures.

Solution

Modified _register_fixture, _getautousenames, and _matchfactories in src/_pytest/fixtures.py:

  1. When registering an autouse fixture for a Directory node, also store it by nodeid string in _nodeid_autousenames
  2. When looking up autouse fixtures, check the nodeid-keyed table for Directory nodes
  3. When matching factories, yield fixtures when the fixture's baseid matches a Directory's nodeid

Assisted-by: Claude Opus 4.6

Fixes pytest-dev#14964

Conftest fixtures are silently missing for files collected after
a file argument from an ancestor directory (pytest 9.1.0+, regression from pytest-dev#14004).

When registering an autouse fixture for a Directory node, also store
it by nodeid string in _nodeid_autousenames. When looking up autouse
fixtures, check the nodeid-keyed table for Directory nodes.

Assisted-by: Claude Opus 4.6
@RonnyPfannschmidt RonnyPfannschmidt changed the title fix: register conftest fixtures by nodeid for Directory nodes [Rejected ai slop]fix: register conftest fixtures by nodeid for Directory nodes Sep 3, 2026
@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Absolutely minimal change that fixes the wrong thing in the wrong place

No tests and no propper analysis was done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

conftest.py fixtures silently missing for files collected after a file argument from an ancestor directory (pytest 9.1.0+, regression from #14004)

2 participants