Repository navigation
fix: deduplicate Directory nodes on re-collection to preserve fixture identity (backport #14635) - #14974
Closed
wahajahmed010 wants to merge 1 commit into
Closed
fix: deduplicate Directory nodes on re-collection to preserve fixture identity (backport #14635)#14974wahajahmed010 wants to merge 1 commit into
wahajahmed010 wants to merge 1 commit into
Conversation
… identity Backport of pytest-dev#14635 to the 9.1.x branch to fix pytest-dev#14964. When Session re-collects a parent Directory (handle_dupes=False for file CLI args), fresh child nodes were created. Since fixture registration uses node identity for matching, the new Directory children didn't match fixtures registered with the original instances. Reuse previously-seen Directory children (by path) when re-collecting a parent. Module/File nodes are still recreated to preserve --keep-duplicates behavior.
Member
|
Hideous untested clone of #14968 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #14635 to the 9.1.x branch to fix #14964.
When a test file is passed directly on the command line (e.g. pytest tests/a.py test_x.py tests/b.py), Session.collect re-collects the parent Directory with handle_dupes=False, which previously created fresh child Directory nodes. Since fixture registration in 9.1.x+ uses node identity for matching, fixtures registered against the original Directory instance became invisible to items collected under the new one, causing conftest fixtures to be silently missing.
Reproduction (from #14964)
Expected: test_a and test_b both fail during setup because of the autouse=True guard fixture in tests/conftest.py.
Observed on 9.1.1: only test_a errors; test_b passes — the conftest fixtures were missing from its fixture closure.
Fix
This is the backport of commit fc8f56b from main (#14635):
When _collect_one_node re-collects a parent Directory that is already in _collection_cache, reuse the previously-seen Directory children by path. Module/File nodes are still recreated to preserve --keep-duplicates behavior.
Changelog
Added changelog/14964.bugfix.rst per the contribution guidelines.
Fixes #14964