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

Method __init__

src/_pytest/pytester.py:682–720  ·  view source on GitHub ↗
(
        self,
        request: FixtureRequest,
        tmp_path_factory: TempPathFactory,
        *,
        _ispytest: bool = False,
    )

Source from the content-addressed store, hash-verified

680 pass
681
682 def __init__(
683 self,
684 request: FixtureRequest,
685 tmp_path_factory: TempPathFactory,
686 *,
687 _ispytest: bool = False,
688 ) -> None:
689 check_ispytest(_ispytest)
690 self._request = request
691 self._mod_collections: WeakKeyDictionary[
692 Collector, List[Union[Item, Collector]]
693 ] = WeakKeyDictionary()
694 if request.function:
695 name: str = request.function.__name__
696 else:
697 name = request.node.name
698 self._name = name
699 self._path: Path = tmp_path_factory.mktemp(name, numbered=True)
700 self.plugins: List[Union[str, _PluggyPlugin]] = []
701 self._cwd_snapshot = CwdSnapshot()
702 self._sys_path_snapshot = SysPathsSnapshot()
703 self._sys_modules_snapshot = self.__take_sys_modules_snapshot()
704 self.chdir()
705 self._request.addfinalizer(self._finalize)
706 self._method = self._request.config.getoption("--runpytest")
707 self._test_tmproot = tmp_path_factory.mktemp(f"tmp-{name}", numbered=True)
708
709 self._monkeypatch = mp = MonkeyPatch()
710 mp.setenv("PYTEST_DEBUG_TEMPROOT", str(self._test_tmproot))
711 # Ensure no unexpected caching via tox.
712 mp.delenv("TOX_ENV_DIR", raising=False)
713 # Discard outer pytest options.
714 mp.delenv("PYTEST_ADDOPTS", raising=False)
715 # Ensure no user config is used.
716 tmphome = str(self.path)
717 mp.setenv("HOME", tmphome)
718 mp.setenv("USERPROFILE", tmphome)
719 # Do not use colors for inner runs by default.
720 mp.setenv("PY_COLORS", "0")
721
722 @property
723 def path(self) -> Path:

Callers

nothing calls this directly

Calls 11

chdirMethod · 0.95
setenvMethod · 0.95
delenvMethod · 0.95
check_ispytestFunction · 0.90
MonkeyPatchClass · 0.90
CwdSnapshotClass · 0.85
SysPathsSnapshotClass · 0.85
mktempMethod · 0.45
addfinalizerMethod · 0.45
getoptionMethod · 0.45

Tested by

no test coverage detected