Skip to content

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

Merged
RonnyPfannschmidt merged 1 commit into
9.1.xfrom
patchback/backports/9.1.x/a933cf5de4d64192d1d588a851ca4e76eec71efc/pr-14645
Sep 6, 2026
Merged

RonnyPfannschmidt merged 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)
@RonnyPfannschmidt
RonnyPfannschmidt merged commit aef551a into 9.1.x Sep 6, 2026
36 checks passed
@RonnyPfannschmidt
RonnyPfannschmidt deleted the patchback/backports/9.1.x/a933cf5de4d64192d1d588a851ca4e76eec71efc/pr-14645 branch September 6, 2026 07:35
cya pushed a commit to cya/TaskQ that referenced this pull request Sep 19, 2026
…erleaved args resolve (issue AZX-PBC-OSS#273)

pytest 9.1.1 drops a nested conftest's fixtures for a test file REVISITED
non-adjacently in the argument list: pytest tests/web_admin/test_factory.py
tests/test_zero_value_convention.py tests/web_admin/test_queues.py errored
on every test in the revisited file with "fixture 'stub_pool' not found"
while the adjacent ordering passed. Upstream pytest-dev/pytest#14971:
collection builds a second Directory node for the revisited directory and
fixture registration matches by node identity, so fixtures registered under
the first instance are invisible to items collected under the second.

Move the web_admin fixtures out of tests/web_admin/conftest.py into
tests/web_admin/_fixtures.py and register them from tests/conftest.py,
which loads for every test regardless of argument order. The autouse env
fixture is path-gated to tests/web_admin/ so its mutations stay scoped to
the suite that had them before. Root-level guard pins both orderings plus
an upstream-behavior probe version-gated on the pytest-dev/pytest#14968
backport.
rcbevans added a commit to AZX-PBC-OSS/TaskQ that referenced this pull request Sep 23, 2026
…ping (#447)

* test: the interleaved-args probe runs unconditionally instead of skipping

pytest-dev/pytest#14968 (the 9.1.x backport of the pytest-dev/pytest#14971
fix) is still unreleased: PyPI's newest pytest is 9.1.1, so there is no
version to adopt and the upstream-behavior probe version-gated on (9, 2, 0)
skipped on every board, verifying nothing.

The upstream bug is specific to fixtures defined in a nested conftest.py
(re-collection of the revisited directory builds a second Directory node and
fixture registration matches by node identity). Fixtures that do not ride a
re-collected Directory node - the root conftest.py and each test module's
own fixtures - resolve under the same interleaving; verified against 9.1.1
and 8.4.2 scratch projects, with the nested-conftest negative control
erroring on 9.1.1 exactly as upstream reports.

Replace the skip with a probe of that scenario: root conftest fixture plus
per-module fixtures, asserted under both argument orderings. The nested
conftest shape stays covered at the repo level by the two guards (web_admin
fixtures registered from tests/conftest.py). A nested-conftest variant of
the probe can be added once the pin moves past the release that ships the
backport.

* ci: board the queue

* ci: re-board

---------

Co-authored-by: rich <rich@local>
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