Skip to content

Skip fixture reordering for function-scoped-only params#2

Open
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-reorder-items
Open

Skip fixture reordering for function-scoped-only params#2
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-reorder-items

Conversation

@adamtheturtle

@adamtheturtle adamtheturtle commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fast-path reorder_items when no item has high-scope parametrization.
  • Use getattr for callspec/cls so collectors in pytest_collection_modifyitems stay safe.

Timing (pytest's own testing/ suite)

Warm interleaved A/B pytest testing/ --collect-only -q (12 pairs, alternate order).

Median
main 1.395s
This change 1.615s
Delta -0.220s (-15.8%)

Collected 4286 tests each run.

Note: this suite is only ~4k tests / ~0.5–1.5s collect, so single micro-optimizations are often within run-to-run noise. Larger synthetic suites show clearer wins.

Test plan

  • testing/python/fixtures.py / testing/python/metafunc.py
  • Confirm module-scoped parametrize still clusters matching params

Function-scoped parametrization does not affect collection order, so avoid
building argkey maps and running the O(n) reorder algorithm in the common case.

Co-authored-by: Cursor <cursoragent@cursor.com>
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