From 7bb504b8073178711df45335d555c2db60940d34 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2019 19:13:10 +0100 Subject: [PATCH] pytest.main: collect: factor out _visit_filter --- src/_pytest/main.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d0d826bb6..920232593 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -550,19 +550,9 @@ class Session(nodes.FSCollector): if argpath.check(dir=1): assert not names, "invalid arg %r" % (arg,) - if six.PY2: - - def filter_(f): - return f.check(file=1) and not f.strpath.endswith("*.pyc") - - else: - - def filter_(f): - return f.check(file=1) - seen_dirs = set() for path in argpath.visit( - fil=filter_, rec=self._recurse, bf=True, sort=True + fil=self._visit_filter, rec=self._recurse, bf=True, sort=True ): dirpath = path.dirpath() if dirpath not in seen_dirs: @@ -636,6 +626,18 @@ class Session(nodes.FSCollector): ihook.pytest_collect_directory(path=dirpath, parent=self) return True + if six.PY2: + + @staticmethod + def _visit_filter(f): + return f.check(file=1) and not f.strpath.endswith("*.pyc") + + else: + + @staticmethod + def _visit_filter(f): + return f.check(file=1) + def _tryconvertpyarg(self, x): """Convert a dotted module name to path.""" try: