From 2b50911c9d9e7cc2c3ffa38c70bff398109718ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Hovm=C3=B6ller?= Date: Thu, 25 Oct 2018 15:16:10 +0200 Subject: [PATCH] Minor refactor for readability Time: 5.73s => 5.88s/5.82s --- src/_pytest/main.py | 11 +++++++---- src/_pytest/python.py | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index dbe1ccf42..9a0162f06 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -533,17 +533,20 @@ class Session(nodes.FSCollector): 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): + 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): - if (type(x), x.fspath) in self._node_cache: - yield self._node_cache[(type(x), x.fspath)] + key = (type(x), x.fspath) + if key in self._node_cache: + yield self._node_cache[key] else: - self._node_cache[(type(x), x.fspath)] = x + self._node_cache[key] = x yield x else: assert argpath.check(file=1) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 2eb5f0b87..6b113cacd 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -563,6 +563,10 @@ class Package(Module): yield Module(init_module, self) pkg_prefixes = set() for path in this_path.visit(rec=self._recurse, bf=True, sort=True): + # We will visit our own __init__.py file, in which case we skip it. + if path.isfile(): + if path.basename == "__init__.py" and path.dirpath() == this_path: + continue parts_ = parts(path.strpath) if any(