Skip to content

Defer TopRequest creation until first access#12

Open
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-lazy-request
Open

Defer TopRequest creation until first access#12
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-lazy-request

Conversation

@adamtheturtle

Copy link
Copy Markdown
Owner

Summary

  • Defer TopRequest until item._request is first read (or setup/run).
  • Keep post-collection item._request access working via lazy init; teardown clearing does not recreate it.

Timing (pytest's own testing/ suite)

Warm interleaved A/B pytest testing/ --collect-only -q (8 pairs).

Median
main 0.665s
This change 0.625s
Delta +0.040s (+6.0%)

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.

Test plan

  • testing/test_runner.py::...::test_keyboardinterrupt_clears_request_and_funcargs
  • testing/python/fixtures.py::TestRequestBasic

Made with Cursor

Collect-only paths that never touch the fixture request skip constructing
TopRequest. Reading item._request after collection still works via lazy init;
teardown clearing does not immediately recreate it.

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