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

Method _getconftestmodules

src/_pytest/config/__init__.py:541–568  ·  view source on GitHub ↗
(
        self, path: Path, importmode: Union[str, ImportMode], rootpath: Path
    )

Source from the content-addressed store, hash-verified

539 self._getconftestmodules(x, importmode, rootpath)
540
541 def _getconftestmodules(
542 self, path: Path, importmode: Union[str, ImportMode], rootpath: Path
543 ) -> List[types.ModuleType]:
544 if self._noconftest:
545 return []
546
547 directory = self._get_directory(path)
548
549 # Optimization: avoid repeated searches in the same directory.
550 # Assumes always called with same importmode and rootpath.
551 existing_clist = self._dirpath2confmods.get(directory)
552 if existing_clist is not None:
553 return existing_clist
554
555 # XXX these days we may rather want to use config.rootpath
556 # and allow users to opt into looking into the rootdir parent
557 # directories instead of requiring to specify confcutdir.
558 clist = []
559 confcutdir_parents = self._confcutdir.parents if self._confcutdir else []
560 for parent in reversed((directory, *directory.parents)):
561 if parent in confcutdir_parents:
562 continue
563 conftestpath = parent / "conftest.py"
564 if conftestpath.is_file():
565 mod = self._importconftest(conftestpath, importmode, rootpath)
566 clist.append(mod)
567 self._dirpath2confmods[directory] = clist
568 return clist
569
570 def _rget_with_confmod(
571 self,

Calls 3

_importconftestMethod · 0.95
appendMethod · 0.80
getMethod · 0.45