Skip to content

Commit fe0a76e

Browse files
committed
Fix recursion bug if a pytest_ignore_collect returns False instead of None
1 parent dcafb8c commit fe0a76e

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

changelog/3771.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix infinite recursion during collection if a ``pytest_ignore_collect`` returns ``False`` instead of ``None``.

src/_pytest/python.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
561561
def _recurse(self, path):
562562
ihook = self.gethookproxy(path.dirpath())
563563
if ihook.pytest_ignore_collect(path=path, config=self.config):
564-
return
564+
return False
565565
for pat in self._norecursepatterns:
566566
if path.check(fnmatch=pat):
567567
return False
@@ -594,9 +594,12 @@ def isinitpath(self, path):
594594
return path in self.session._initialpaths
595595

596596
def collect(self):
597-
path = self.fspath.dirpath()
597+
this_path = self.fspath.dirpath()
598598
pkg_prefix = None
599-
for path in path.visit(fil=lambda x: 1, rec=self._recurse, bf=True, sort=True):
599+
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):
600+
# we will visit our own __init__.py file, in which case we skip it
601+
if path.basename == "__init__.py" and path.dirpath() == this_path:
602+
continue
600603
if pkg_prefix and pkg_prefix in path.parts():
601604
continue
602605
for x in self._collectfile(path):

0 commit comments

Comments
 (0)