MCPcopy
hub / github.com/pytest-dev/pytest / collect

Method collect

src/_pytest/python.py:695–720  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

693 self.addfinalizer(func)
694
695 def collect(self) -> Iterable[nodes.Item | nodes.Collector]:
696 # Always collect __init__.py first.
697 def sort_key(entry: os.DirEntry[str]) -> object:
698 return (entry.name != "__init__.py", entry.name)
699
700 config = self.config
701 col: nodes.Collector | None
702 cols: Sequence[nodes.Collector]
703 ihook = self.ihook
704 for direntry in scandir(self.path, sort_key):
705 if direntry.is_dir():
706 path = Path(direntry.path)
707 if not self.session.isinitpath(path, with_parents=True):
708 if ihook.pytest_ignore_collect(collection_path=path, config=config):
709 continue
710 col = ihook.pytest_collect_directory(path=path, parent=self)
711 if col is not None:
712 yield col
713
714 elif direntry.is_file():
715 path = Path(direntry.path)
716 if not self.session.isinitpath(path):
717 if ihook.pytest_ignore_collect(collection_path=path, config=config):
718 continue
719 cols = ihook.pytest_collect_file(file_path=path, parent=self)
720 yield from cols
721
722
723def _call_with_optional_argument(func, arg) -> None:

Callers

nothing calls this directly

Calls 3

scandirFunction · 0.90
pytest_collect_fileMethod · 0.80
isinitpathMethod · 0.45

Tested by

no test coverage detected