pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.67k stars 2.59k forks source link

Warn if collection spends >5s traversing a directory without collecting any tests #12312

Open Zac-HD opened 2 months ago

Zac-HD commented 2 months ago

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.

Pierre-Sassoulas commented 2 months ago

Kinda related, but maybe when the --durations option is used, we also display the collection time per directory ?