Skip to content

Fix #14942: avoid quadratic fixture registration - #14947

Closed
timothyanderson096-ocdealcheck wants to merge 1 commit into
pytest-dev:mainfrom
timothyanderson096-ocdealcheck:fix-14942-collection-performance
Closed

Fix #14942: avoid quadratic fixture registration#14947
timothyanderson096-ocdealcheck wants to merge 1 commit into
pytest-dev:mainfrom
timothyanderson096-ocdealcheck:fix-14942-collection-performance

Conversation

@timothyanderson096-ocdealcheck

Copy link
Copy Markdown

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:

  • before the fix: 780 visibility comparisons;
  • after the fix: below the linear ceiling;
  • all 40 fixtures still resolve to their class-local value.

Validation

  • python -m pytest -q testing/python/fixtures.py — 241 passed, 1 skipped, 2 xfailed
  • python -m pytest -q testing/test_collection.py testing/test_main.py — passed, expected skips/xfail
  • pre-commit run --files AUTHORS src/_pytest/fixtures.py testing/python/fixtures.py changelog/14942.bugfix.rst — passed

This contribution was developed with AI assistance under human supervision; the AI tool is credited in the commit trailer.

Co-authored-by: OpenAI Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test collection is 10x slower on 9.1.1 compared to 9.0.3

2 participants