Speed up test collection for large suites#1
Open
adamtheturtle wants to merge 5 commits into
Open
Conversation
Cache path-sensitive hook proxies, skip unnecessary fixture reordering, and avoid expensive signature/path work on common collection hot paths. Co-authored-by: Cursor <cursoragent@cursor.com>
Reuse FunctionDefinition nodes for non-parametrized tests, defer TopRequest until setup, share resolved markers across parametrized items, and build the first CallSpec2 batch without empty-map copies. Co-authored-by: Cursor <cursoragent@cursor.com>
Declare callspec on Item, type hook proxies as HookRelay | FSHookProxy, model request lifecycle with Optional instead of False, and reuse FunctionDefinition via a runnable flag instead of mutating __class__. Co-authored-by: Cursor <cursoragent@cursor.com>
Restores post-collection item._request compatibility while still skipping TopRequest construction on collect-only paths that never read it, and keeps teardown clearing from immediately recreating the request. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b514004. Configure here.
Caching an FSHookProxy when a path's directory was not yet in _dirpath2confmods permanently stripped root conftests from Package collection, because later association does not grow _conftest_plugins. Co-authored-by: Cursor <cursoragent@cursor.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.

Summary
Session.gethookproxyresults and invalidate when new conftests load (addresses_pytest.main.Session.gethookproxyis called many times with the same argument on large suites pytest-dev/pytest#8991 without regressing pytest_ignore_collect applies to all directories collected afterwards? pytest-dev/pytest#2016).getfuncargnames,_get_directory,Node.__hash__,FunctionDefinitionsetup, assertion-rewrite tree walk).--collect-onlybenchmark, median collection time dropped from ~4.05s to ~1.92s (~2×).Test plan
testing/test_pluginmanager.py::TestPytestPluginInteractions::test_hook_proxytesting/test_conftest.py::test_hook_proxytesting/test_assertion.py::test_assertrepr_loaded_per_dirtesting/python/fixtures.pygetfuncargnames tests + fixtures/metafunc/scope/assertion suitesMade with Cursor