Skip to content

Commit 827573c

Browse files
committed
cleanup, TODO: use _node_cache
1 parent 6fce1f0 commit 827573c

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/_pytest/main.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ def _collect(self, arg):
490490
names = self._parsearg(arg)
491491
argpath = names.pop(0).realpath()
492492

493-
root = self
494493
# Start with a Session root, and delve to argpath item (dir or file)
495494
# and stack all Packages found on the way.
496495
# No point in finding packages when collecting doctests
@@ -503,10 +502,8 @@ def _collect(self, arg):
503502
if parent.isdir():
504503
pkginit = parent.join("__init__.py")
505504
if pkginit.isfile():
506-
if pkginit in self._node_cache:
507-
root = self._node_cache[pkginit][0]
508-
else:
509-
col = root._collectfile(pkginit, handle_dupes=False)
505+
if pkginit not in self._node_cache:
506+
col = self._collectfile(pkginit, handle_dupes=False)
510507
if col:
511508
if isinstance(col[0], Package):
512509
self._pkg_roots[parent] = col[0]
@@ -533,27 +530,21 @@ def filter_(f):
533530
fil=filter_, rec=self._recurse, bf=True, sort=True
534531
):
535532
dirpath = path.dirpath()
536-
collect_root = self._pkg_roots.get(dirpath, root)
537533
if dirpath not in seen_dirs:
538534
# Collect packages first.
539535
seen_dirs.add(dirpath)
540536
pkginit = dirpath.join("__init__.py")
541537
if pkginit.exists():
542-
got_pkg = False
538+
collect_root = self._pkg_roots.get(dirpath, self)
543539
for x in collect_root._collectfile(pkginit):
544540
yield x
545541
if isinstance(x, Package):
546542
self._pkg_roots[dirpath] = x
547-
got_pkg = True
548-
if got_pkg:
549-
continue
550-
if path.basename == "__init__.py":
551-
continue
552-
553543
if dirpath in self._pkg_roots:
544+
# Do not collect packages here.
554545
continue
555546

556-
for x in collect_root._collectfile(path):
547+
for x in self._collectfile(path):
557548
key = (type(x), x.fspath)
558549
if key in self._node_cache:
559550
yield self._node_cache[key]
@@ -566,7 +557,7 @@ def filter_(f):
566557
if argpath in self._node_cache:
567558
col = self._node_cache[argpath]
568559
else:
569-
collect_root = self._pkg_roots.get(argpath.dirname, root)
560+
collect_root = self._pkg_roots.get(argpath.dirname, self)
570561
col = collect_root._collectfile(argpath)
571562
if col:
572563
self._node_cache[argpath] = col

0 commit comments

Comments
 (0)