Skip to content

Commit

Permalink
paths: use set and isdisjoint
Browse files Browse the repository at this point in the history
Time: 5.36s => 4.85s (before rebase: 4.45s => 3.55s)
  • Loading branch information
blueyed committed Nov 2, 2018
1 parent 6ffa347 commit 023e1c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def _collect(self, arg):

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)
Expand Down Expand Up @@ -537,14 +537,12 @@ def filter_(f):
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:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))}

0 comments on commit 023e1c7

Please sign in to comment.