Skip to content

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed
 

‎changelog/11081.improvement.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :confval:`norecursedir` check is now performed in a :hook:`pytest_ignore_collect` implementation, so plugins can affect it.

‎src/_pytest/main.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ def pytest_ignore_collect(collection_path: Path, config: Config) -> Optional[boo
400400
allow_in_venv = config.getoption("collect_in_virtualenv")
401401
if not allow_in_venv and _in_venv(collection_path):
402402
return True
403+
404+
if collection_path.is_dir():
405+
norecursepatterns = config.getini("norecursedirs")
406+
if any(fnmatch_ex(pat, collection_path) for pat in norecursepatterns):
407+
return True
408+
403409
return None
404410

405411

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

571574
def _collectfile(

‎src/_pytest/python.py

-3
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,6 @@ def _recurse(self, direntry: "os.DirEntry[str]") -> bool:
706706
ihook = self.session.gethookproxy(fspath.parent)
707707
if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config):
708708
return False
709-
norecursepatterns = self.config.getini("norecursedirs")
710-
if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns):
711-
return False
712709
return True
713710

714711
def _collectfile(

0 commit comments

Comments
 (0)
Please sign in to comment.