pytest
pytest copied to clipboard
Warn if collection spends >5s traversing a directory without collecting any tests
I recently saw https://github.com/pytest-dev/pytest/issues/5851#issuecomment-2094075457, which made me wonder if we could automatically detect similar cases and suggest using the --ignore flag or norecursedirs config option.
Tracking the time spent in collection on a per-directory basis and whether any test files were collected should be pretty straightforward, and from there it's just the reporting code. Specifically: depth-first search over the tree, don't recurse into children if the current node triggered the warning or took <= 5s. Alternatively, maybe this could be integrated with the collection code so that we don't need a separate step.
Kinda related, but maybe when the --durations option is used, we also display the collection time per directory ?