Skip to content

Commit c1f9756

Browse files
committed
main: couple of code simplifications
1 parent 023f051 commit c1f9756

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/_pytest/main.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,8 @@ def _recurse(self, direntry: "os.DirEntry[str]") -> bool:
511511
if ihook.pytest_ignore_collect(path=path, config=self.config):
512512
return False
513513
norecursepatterns = self.config.getini("norecursedirs")
514-
for pat in norecursepatterns:
515-
if path.check(fnmatch=pat):
516-
return False
514+
if any(path.check(fnmatch=pat) for pat in norecursepatterns):
515+
return False
517516
return True
518517

519518
def _collectfile(
@@ -650,13 +649,12 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
650649

651650
if parent.isdir():
652651
pkginit = parent.join("__init__.py")
653-
if pkginit.isfile():
654-
if pkginit not in node_cache1:
655-
col = self._collectfile(pkginit, handle_dupes=False)
656-
if col:
657-
if isinstance(col[0], Package):
658-
pkg_roots[str(parent)] = col[0]
659-
node_cache1[col[0].fspath] = [col[0]]
652+
if pkginit.isfile() and pkginit not in node_cache1:
653+
col = self._collectfile(pkginit, handle_dupes=False)
654+
if col:
655+
if isinstance(col[0], Package):
656+
pkg_roots[str(parent)] = col[0]
657+
node_cache1[col[0].fspath] = [col[0]]
660658

661659
# If it's a directory argument, recurse and look for any Subpackages.
662660
# Let the Package collector deal with subnodes, don't collect here.

src/_pytest/python.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,8 @@ def _recurse(self, direntry: "os.DirEntry[str]") -> bool:
644644
if ihook.pytest_ignore_collect(path=path, config=self.config):
645645
return False
646646
norecursepatterns = self.config.getini("norecursedirs")
647-
for pat in norecursepatterns:
648-
if path.check(fnmatch=pat):
649-
return False
647+
if any(path.check(fnmatch=pat) for pat in norecursepatterns):
648+
return False
650649
return True
651650

652651
def _collectfile(

0 commit comments

Comments
 (0)