-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix infinite recursion collection bug with pytest_ignore_collect hook #3771
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix infinite recursion during collection if a ``pytest_ignore_collect`` returns ``False`` instead of ``None``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix. I did not understand what this had to do with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def pytest_ignore_collect(path): | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test(): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't have anything to do with the fix, just thought I would keep the return value consistent.