Permalink
Browse files

Merge pull request #3771 from nicoddemus/package-infinite-recursion-bug

Fix infinite recursion collection bug with pytest_ignore_collect hook
  • Loading branch information...
nicoddemus committed Aug 6, 2018
2 parents 855fd17 + fe0a76e commit e7230691652ff31fcc1cd92e4f5bf080f386b681
@@ -0,0 +1 @@
Fix infinite recursion during collection if a ``pytest_ignore_collect`` returns ``False`` instead of ``None``.
View
@@ -561,7 +561,7 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
def _recurse(self, path):
ihook = self.gethookproxy(path.dirpath())
if ihook.pytest_ignore_collect(path=path, config=self.config):

This comment has been minimized.

Show comment
Hide comment
@jonozzz

jonozzz Aug 10, 2018

I'm not sure why we need this if anyway. This is causing #3768

@jonozzz

jonozzz Aug 10, 2018

I'm not sure why we need this if anyway. This is causing #3768

return
return False
for pat in self._norecursepatterns:
if path.check(fnmatch=pat):
return False
@@ -594,9 +594,12 @@ def isinitpath(self, path):
return path in self.session._initialpaths
def collect(self):
path = self.fspath.dirpath()
this_path = self.fspath.dirpath()
pkg_prefix = None
for path in path.visit(fil=lambda x: 1, rec=self._recurse, bf=True, sort=True):
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):
# we will visit our own __init__.py file, in which case we skip it
if path.basename == "__init__.py" and path.dirpath() == this_path:
continue
if pkg_prefix and pkg_prefix in path.parts():
continue
for x in self._collectfile(path):
@@ -0,0 +1,2 @@
def pytest_ignore_collect(path):
return False
@@ -1577,3 +1577,9 @@ def test_real():
)
result = testdir.runpytest("--keep-duplicates", a.strpath, a.strpath)
result.stdout.fnmatch_lines(["*collected 2 item*"])
def test_package_collection_infinite_recursion(testdir):
testdir.copy_example("collect/package_infinite_recursion")
result = testdir.runpytest()
result.stdout.fnmatch_lines("*1 passed*")

0 comments on commit e723069

Please sign in to comment.