Skip to content

Commit 3acbdc2

Browse files
Merge pull request #11814 from bluetech/pycache-ignore-collect
main,python: move `__pycache__` ignore to `pytest_ignore_collect`
2 parents 2bb0eca + 2413d1b commit 3acbdc2

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/_pytest/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ def _in_venv(path: Path) -> bool:
376376

377377

378378
def pytest_ignore_collect(collection_path: Path, config: Config) -> Optional[bool]:
379+
if collection_path.name == "__pycache__":
380+
return True
381+
379382
ignore_paths = config._getconftest_pathlist(
380383
"collect_ignore", path=collection_path.parent
381384
)
@@ -505,8 +508,6 @@ def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
505508
ihook = self.ihook
506509
for direntry in scandir(self.path):
507510
if direntry.is_dir():
508-
if direntry.name == "__pycache__":
509-
continue
510511
path = Path(direntry.path)
511512
if not self.session.isinitpath(path, with_parents=True):
512513
if ihook.pytest_ignore_collect(collection_path=path, config=config):

src/_pytest/python.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,6 @@ def sort_key(entry: "os.DirEntry[str]") -> object:
707707
ihook = self.ihook
708708
for direntry in scandir(self.path, sort_key):
709709
if direntry.is_dir():
710-
if direntry.name == "__pycache__":
711-
continue
712710
path = Path(direntry.path)
713711
if not self.session.isinitpath(path, with_parents=True):
714712
if ihook.pytest_ignore_collect(collection_path=path, config=config):

0 commit comments

Comments
 (0)