Skip to content

Commit e609bf1

Browse files
committed
squash! _recurse: skip __pycache__
Fix __pycache__/.pyc handling. Time: 3.51s => 3.23
1 parent 2eab084 commit e609bf1

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/_pytest/main.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,21 @@ def _collect(self, arg):
528528
if argpath.check(dir=1):
529529
assert not names, "invalid arg %r" % (arg,)
530530

531+
if six.PY2:
532+
533+
def filter_(f):
534+
return f.check(file=1) and f.strpath.endswith("*.pyc")
535+
536+
else:
537+
538+
def filter_(f):
539+
if f.check(file=1):
540+
assert not f.strpath.endswith("*.pyc")
541+
return f.check(file=1)
542+
531543
seen_dirs = set()
532544
for path in argpath.visit(
533-
fil=lambda x: x.check(file=1), rec=self._recurse, bf=True, sort=True
545+
fil=filter_, rec=self._recurse, bf=True, sort=True
534546
):
535547
dirpath = path.dirpath()
536548
if dirpath not in seen_dirs:
@@ -568,18 +580,17 @@ def _collectfile(self, path):
568580
return ()
569581
return ihook.pytest_collect_file(path=path, parent=self)
570582

571-
def _recurse(self, path):
572-
dirpath = path.dirpath()
583+
def _recurse(self, dirpath):
573584
if dirpath.basename == "__pycache__":
574-
return True
575-
ihook = self.gethookproxy(dirpath)
576-
if ihook.pytest_ignore_collect(path=path, config=self.config):
585+
return
586+
ihook = self.gethookproxy(dirpath.dirpath())
587+
if ihook.pytest_ignore_collect(path=dirpath, config=self.config):
577588
return
578589
for pat in self._norecursepatterns:
579-
if path.check(fnmatch=pat):
590+
if dirpath.check(fnmatch=pat):
580591
return False
581-
ihook = self.gethookproxy(path)
582-
ihook.pytest_collect_directory(path=path, parent=self)
592+
ihook = self.gethookproxy(dirpath)
593+
ihook.pytest_collect_directory(path=dirpath, parent=self)
583594
return True
584595

585596
def _tryconvertpyarg(self, x):

src/_pytest/python.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,17 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
517517
self._norecursepatterns = session._norecursepatterns
518518
self.fspath = fspath
519519

520-
def _recurse(self, path):
521-
ihook = self.gethookproxy(path.dirpath())
522-
if ihook.pytest_ignore_collect(path=path, config=self.config):
523-
return False
520+
def _recurse(self, dirpath):
521+
if dirpath.basename == "__pycache__":
522+
return
523+
ihook = self.gethookproxy(dirpath.dirpath())
524+
if ihook.pytest_ignore_collect(path=dirpath, config=self.config):
525+
return
524526
for pat in self._norecursepatterns:
525-
if path.check(fnmatch=pat):
527+
if dirpath.check(fnmatch=pat):
526528
return False
527-
ihook = self.gethookproxy(path)
528-
ihook.pytest_collect_directory(path=path, parent=self)
529+
ihook = self.gethookproxy(dirpath)
530+
ihook.pytest_collect_directory(path=dirpath, parent=self)
529531
return True
530532

531533
def gethookproxy(self, fspath):

0 commit comments

Comments
 (0)