Fix #14942: avoid quadratic fixture registration - #14947
Closed
timothyanderson096-ocdealcheck wants to merge 1 commit into
Closed
Fix #14942: avoid quadratic fixture registration#14947timothyanderson096-ocdealcheck wants to merge 1 commit into
timothyanderson096-ocdealcheck wants to merge 1 commit into
Conversation
Co-authored-by: OpenAI Codex <codex@openai.com>
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.
Closes #14942.
Summary
Fixture definitions with the same name are kept in visibility order. Registration previously scanned the complete list for every new definition, even when definitions belonged to unrelated sibling classes and therefore could never override one another. That made this common class-heavy pattern quadratic.
This change records, per fixture name, the collection nodes that are strict ancestors of an existing definition. A new definition on an unrelated node can then append directly. The complete comparison path remains in place for late-registered ancestors and for deprecated string-nodeid visibility, preserving the existing precedence rules.
Regression coverage
The new test collects 40 sibling classes defining the same fixture name:
Validation
python -m pytest -q testing/python/fixtures.py— 241 passed, 1 skipped, 2 xfailedpython -m pytest -q testing/test_collection.py testing/test_main.py— passed, expected skips/xfailpre-commit run --files AUTHORS src/_pytest/fixtures.py testing/python/fixtures.py changelog/14942.bugfix.rst— passedThis contribution was developed with AI assistance under human supervision; the AI tool is credited in the commit trailer.