Skip to content

Commit

Permalink
main: move norecursedir check to main's pytest_ignore_collect
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Jun 5, 2023
1 parent 85c5bd2 commit ae38b07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/11081.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :confval:`norecursedir` check is now performed in a :hook:`pytest_ignore_collect` implementation, so plugins can affect it.
9 changes: 6 additions & 3 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ def pytest_ignore_collect(collection_path: Path, config: Config) -> Optional[boo
allow_in_venv = config.getoption("collect_in_virtualenv")
if not allow_in_venv and _in_venv(collection_path):
return True

if collection_path.is_dir():
norecursepatterns = config.getini("norecursedirs")
if any(fnmatch_ex(pat, collection_path) for pat in norecursepatterns):
return True

return None


Expand Down Expand Up @@ -563,9 +569,6 @@ def _recurse(self, direntry: "os.DirEntry[str]") -> bool:
ihook = self.gethookproxy(fspath.parent)
if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config):
return False
norecursepatterns = self.config.getini("norecursedirs")
if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns):
return False
return True

def _collectfile(
Expand Down
3 changes: 0 additions & 3 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,6 @@ def _recurse(self, direntry: "os.DirEntry[str]") -> bool:
ihook = self.session.gethookproxy(fspath.parent)
if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config):
return False
norecursepatterns = self.config.getini("norecursedirs")
if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns):
return False
return True

def _collectfile(
Expand Down

0 comments on commit ae38b07

Please sign in to comment.