Skip to content

Commit b4b2f58

Browse files
authored
Merge pull request #4747 from blueyed/visit-filter
pytest.main: collect: factor out _visit_filter
2 parents 8b92d10 + 7bb504b commit b4b2f58

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/_pytest/main.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,19 +550,9 @@ def _collect(self, arg):
550550
if argpath.check(dir=1):
551551
assert not names, "invalid arg %r" % (arg,)
552552

553-
if six.PY2:
554-
555-
def filter_(f):
556-
return f.check(file=1) and not f.strpath.endswith("*.pyc")
557-
558-
else:
559-
560-
def filter_(f):
561-
return f.check(file=1)
562-
563553
seen_dirs = set()
564554
for path in argpath.visit(
565-
fil=filter_, rec=self._recurse, bf=True, sort=True
555+
fil=self._visit_filter, rec=self._recurse, bf=True, sort=True
566556
):
567557
dirpath = path.dirpath()
568558
if dirpath not in seen_dirs:
@@ -637,6 +627,18 @@ def _recurse(self, dirpath):
637627
ihook.pytest_collect_directory(path=dirpath, parent=self)
638628
return True
639629

630+
if six.PY2:
631+
632+
@staticmethod
633+
def _visit_filter(f):
634+
return f.check(file=1) and not f.strpath.endswith("*.pyc")
635+
636+
else:
637+
638+
@staticmethod
639+
def _visit_filter(f):
640+
return f.check(file=1)
641+
640642
def _tryconvertpyarg(self, x):
641643
"""Convert a dotted module name to path."""
642644
try:

0 commit comments

Comments
 (0)