diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 9a0162f06..d67468887 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -529,16 +529,20 @@ class Session(nodes.FSCollector): def filter_(f): return f.check(file=1) + seen_dirs = set() for path in argpath.visit( fil=filter_, rec=self._recurse, bf=True, sort=True ): - pkginit = path.dirpath().join("__init__.py") - if pkginit.exists() and not any( - x in parts(pkginit.strpath) for x in paths - ): - for x in root._collectfile(pkginit): - yield x - paths.append(x.fspath.dirpath()) + dirpath = path.dirpath() + if dirpath not in seen_dirs: + seen_dirs.add(dirpath) + pkginit = dirpath.join("__init__.py") + if pkginit.exists() and not any( + x in parts(pkginit.strpath) for x in paths + ): + for x in root._collectfile(pkginit): + yield x + paths.append(x.fspath.dirpath()) if not any(x in parts(path.strpath) for x in paths): for x in root._collectfile(path):