diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d67468887..de0740744 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -489,7 +489,7 @@ class Session(nodes.FSCollector): names = self._parsearg(arg) argpath = names.pop(0).realpath() - paths = [] + paths = set() root = self # Start with a Session root, and delve to argpath item (dir or file) @@ -537,14 +537,12 @@ class Session(nodes.FSCollector): 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 - ): + if pkginit.exists() and parts(pkginit.strpath).isdisjoint(paths): for x in root._collectfile(pkginit): yield x - paths.append(x.fspath.dirpath()) + paths.add(x.fspath.dirpath()) - if not any(x in parts(path.strpath) for x in paths): + if parts(path.strpath).isdisjoint(paths): for x in root._collectfile(path): key = (type(x), x.fspath) if key in self._node_cache: diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index c907b495c..430e1ec1d 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -307,4 +307,4 @@ def fnmatch_ex(pattern, path): def parts(s): parts = s.split(sep) - return [sep.join(parts[:i+1]) or sep for i in range(len(parts))] + return {sep.join(parts[: i + 1]) or sep for i in range(len(parts))}