From 6ffa347c77344a57cbb99ff43d7c27b78a7b9511 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 25 Oct 2018 17:19:19 +0200 Subject: [PATCH] Handle dirs only once Time: 5.73s/5.88s => 5.36s (Before rebase: 4.86s => 4.45s) --- src/_pytest/main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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):