(self)
| 667 | return items |
| 668 | |
| 669 | def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]: |
| 670 | from _pytest.python import Package |
| 671 | |
| 672 | # Keep track of any collected nodes in here, so we don't duplicate fixtures. |
| 673 | node_cache1: Dict[Path, Sequence[nodes.Collector]] = {} |
| 674 | node_cache2: Dict[Tuple[Type[nodes.Collector], Path], nodes.Collector] = {} |
| 675 | |
| 676 | # Keep track of any collected collectors in matchnodes paths, so they |
| 677 | # are not collected more than once. |
| 678 | matchnodes_cache: Dict[Tuple[Type[nodes.Collector], str], CollectReport] = {} |
| 679 | |
| 680 | # Dirnames of pkgs with dunder-init files. |
| 681 | pkg_roots: Dict[str, Package] = {} |
| 682 | |
| 683 | for argpath, names in self._initial_parts: |
| 684 | self.trace("processing argument", (argpath, names)) |
| 685 | self.trace.root.indent += 1 |
| 686 | |
| 687 | # Start with a Session root, and delve to argpath item (dir or file) |
| 688 | # and stack all Packages found on the way. |
| 689 | # No point in finding packages when collecting doctests. |
| 690 | if not self.config.getoption("doctestmodules", False): |
| 691 | pm = self.config.pluginmanager |
| 692 | confcutdir = pm._confcutdir |
| 693 | for parent in (argpath, *argpath.parents): |
| 694 | if confcutdir and parent in confcutdir.parents: |
| 695 | break |
| 696 | |
| 697 | if parent.is_dir(): |
| 698 | pkginit = parent / "__init__.py" |
| 699 | if pkginit.is_file() and pkginit not in node_cache1: |
| 700 | col = self._collectfile(pkginit, handle_dupes=False) |
| 701 | if col: |
| 702 | if isinstance(col[0], Package): |
| 703 | pkg_roots[str(parent)] = col[0] |
| 704 | node_cache1[col[0].path] = [col[0]] |
| 705 | |
| 706 | # If it's a directory argument, recurse and look for any Subpackages. |
| 707 | # Let the Package collector deal with subnodes, don't collect here. |
| 708 | if argpath.is_dir(): |
| 709 | assert not names, f"invalid arg {(argpath, names)!r}" |
| 710 | |
| 711 | seen_dirs: Set[Path] = set() |
| 712 | for direntry in visit(str(argpath), self._recurse): |
| 713 | if not direntry.is_file(): |
| 714 | continue |
| 715 | |
| 716 | path = Path(direntry.path) |
| 717 | dirpath = path.parent |
| 718 | |
| 719 | if dirpath not in seen_dirs: |
| 720 | # Collect packages first. |
| 721 | seen_dirs.add(dirpath) |
| 722 | pkginit = dirpath / "__init__.py" |
| 723 | if pkginit.exists(): |
| 724 | for x in self._collectfile(pkginit): |
| 725 | yield x |
| 726 | if isinstance(x, Package): |
nothing calls this directly
no test coverage detected