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.
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 ornorecursedirs
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.