Skip to content

[PR #14645/a933cf5d backport][9.1.x] fix: deduplicate Directory nodes on re-collection to preserve fixture identity (#14635) - #14968

Open
patchback[bot] wants to merge 1 commit into
9.1.xfrom
patchback/backports/9.1.x/a933cf5de4d64192d1d588a851ca4e76eec71efc/pr-14645
Open

[PR #14645/a933cf5d backport][9.1.x] fix: deduplicate Directory nodes on re-collection to preserve fixture identity (#14635)#14968
patchback[bot] wants to merge 1 commit into
9.1.xfrom
patchback/backports/9.1.x/a933cf5de4d64192d1d588a851ca4e76eec71efc/pr-14645

Conversation

@patchback

@patchback patchback Bot commented Sep 4, 2026

Copy link
Copy Markdown

This is a backport of PR #14645 as merged into main (a933cf5).

Summary

Fixes #14635.

When Session re-collects a parent Directory (due to handle_dupes=False for file CLI args), fresh child nodes were created. Since fixture registration uses node identity for matching (_matchfactories checks fixturedef.node in parent_nodes), the new Directory children didn't match fixtures registered with the original instances.

This caused fixture closure computation to fail for tests collected after unrelated paths, because the conftest fixtures were registered with a now-orphaned Directory node instance.

Root cause: _collect_one_node with handle_dupes=False calls collect() on the parent Directory, which creates brand-new child Directory/Package instances. The _collection_cache is then updated with these new children. Later collection paths that look up cached children find different node objects than the ones conftest fixtures were registered with.

Fix: After re-collection, replace any freshly-created Directory children with the previously-seen instances for the same path. Module/File nodes are still recreated to preserve --keep-duplicates semantics (which needs fresh test items).

Test plan

Made with Cursor

…e-directory-nodes-on-recollection

fix: deduplicate Directory nodes on re-collection to preserve fixture identity (#14635)
(cherry picked from commit a933cf5)
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.

1 participant