Skip to content

pytest discovery: cache class line numbers to avoid redundant AST parsing - #26242

Open
Abhinav Maurya (Fire162) wants to merge 1 commit into
microsoft:mainfrom
Fire162:fix/pytest-class-node-lineno-perf
Open

Abhinav Maurya (Fire162) wants to merge 1 commit into
microsoft:mainfrom
Fire162:fix/pytest-class-node-lineno-perf

Conversation

@Fire162

Copy link
Copy Markdown

On Python < 3.13, create_class_node repeatedly calls inspect.getsourcelines(), which reparses the entire file AST on every test class.

This reads firstlineno where available and caches parsed class line numbers per file on older Python versions.

Fixes #26240

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.

Pytest discovery: create_class_node re-parses the file for every class on Python < 3.13

1 participant