Merge pull request #4747 from blueyed/visit-filter

pytest.main: collect: factor out _visit_filter
This commit is contained in:
Daniel Hahler 2019-02-08 22:19:38 +01:00 committed by GitHub
commit b4b2f58eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 11 deletions

View File

@ -550,19 +550,9 @@ class Session(nodes.FSCollector):
if argpath.check(dir=1): if argpath.check(dir=1):
assert not names, "invalid arg %r" % (arg,) 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() seen_dirs = set()
for path in argpath.visit( 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() dirpath = path.dirpath()
if dirpath not in seen_dirs: if dirpath not in seen_dirs:
@ -637,6 +627,18 @@ class Session(nodes.FSCollector):
ihook.pytest_collect_directory(path=dirpath, parent=self) ihook.pytest_collect_directory(path=dirpath, parent=self)
return True 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): def _tryconvertpyarg(self, x):
"""Convert a dotted module name to path.""" """Convert a dotted module name to path."""
try: try: