MCPcopy Create free account
hub / github.com/pytest-dev/pytest / collect

Method collect

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

Source from the content-addressed store, hash-verified

726 return ihook.pytest_collect_file(file_path=fspath, parent=self) # type: ignore[no-any-return]
727
728 def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
729 this_path = self.path.parent
730 init_module = this_path / "__init__.py"
731 if init_module.is_file() and path_matches_patterns(
732 init_module, self.config.getini("python_files")
733 ):
734 yield Module.from_parent(self, path=init_module)
735 pkg_prefixes: Set[Path] = set()
736 for direntry in visit(str(this_path), recurse=self._recurse):
737 path = Path(direntry.path)
738
739 # We will visit our own __init__.py file, in which case we skip it.
740 if direntry.is_file():
741 if direntry.name == "__init__.py" and path.parent == this_path:
742 continue
743
744 parts_ = parts(direntry.path)
745 if any(
746 str(pkg_prefix) in parts_ and pkg_prefix / "__init__.py" != path
747 for pkg_prefix in pkg_prefixes
748 ):
749 continue
750
751 if direntry.is_file():
752 yield from self._collectfile(path)
753 elif not direntry.is_dir():
754 # Broken symlink or invalid/missing file.
755 continue
756 elif path.joinpath("__init__.py").is_file():
757 pkg_prefixes.add(path)
758
759
760def _call_with_optional_argument(func, arg) -> None:

Callers

nothing calls this directly

Calls 6

_collectfileMethod · 0.95
visitFunction · 0.90
partsFunction · 0.90
path_matches_patternsFunction · 0.85
getiniMethod · 0.45
from_parentMethod · 0.45

Tested by

no test coverage detected