Skip to content

Reuse FunctionDefinition as Function for non-parametrized tests#11

Open
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-as-function
Open

Reuse FunctionDefinition as Function for non-parametrized tests#11
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/faster-collect-as-function

Conversation

@adamtheturtle

Copy link
Copy Markdown
Owner

Summary

  • For non-parametrized tests, reuse the FunctionDefinition node as the collected Function via as_function() instead of constructing a second Function.

Timing (pytest's own testing/ suite)

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

Median
main 0.590s
This change 0.550s
Delta +0.040s (+6.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.

Test plan

  • testing/python/metafunc.py
  • testing/test_collection.py
  • Method tests (instance binding after clearing cached _obj)

Made with Cursor

Avoid constructing a second Function with identical state when a test has a
single invocation; mark the definition runnable via as_function() instead.

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