You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pytest discovery: create_class_node re-parses the file for every class on Python < 3.13 #26240
To put a line number on class nodes, vscode_pytest.create_class_node() calls inspect.getsourcelines(class_module.obj) once per test class. On Python < 3.13, classes have no __firstlineno__, so inspect.findsource() re-parses the entire module with ast.parse()
and walks the whole AST on every call. A file containing N test classes is therefore parsed N times.
Test discovery that takes ~4.6s with plain pytest takes ~45s in VS Code. During that time the
Testing view is empty and no gutter run buttons are shown.
Nearly all of discovery time goes to findsource → ast.parse for classes. Times are inflated by cProfile overhead (45s wall-clock without profiling); the proportions are what matter.
Only lineno is needed. getsourcelines also extracts the full source block, which is extra work.
On CPython < 3.13, inspect.findsource() for a class runs ast.parse(source) plus a _ClassFinder visit of the whole file on every call. Nothing caches it, so the cost is
O(classes × file size).
On 3.13+ it reads cls.__firstlineno__, which is why 3.13 is fine.
Activity