@@ -477,7 +477,9 @@ def LineMatcher_fixture(request: FixtureRequest) -> Type["LineMatcher"]:
477
477
478
478
479
479
@fixture
480
- def pytester (request : FixtureRequest , tmp_path_factory : TempPathFactory ) -> "Pytester" :
480
+ def pytester (
481
+ request : FixtureRequest , tmp_path_factory : TempPathFactory , monkeypatch : MonkeyPatch
482
+ ) -> "Pytester" :
481
483
"""
482
484
Facilities to write tests/configuration files, execute pytest in isolation, and match
483
485
against expected output, perfect for black-box testing of pytest plugins.
@@ -488,7 +490,7 @@ def pytester(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> "Pyt
488
490
It is particularly useful for testing plugins. It is similar to the :fixture:`tmp_path`
489
491
fixture but provides methods which aid in testing pytest itself.
490
492
"""
491
- return Pytester (request , tmp_path_factory , _ispytest = True )
493
+ return Pytester (request , tmp_path_factory , monkeypatch , _ispytest = True )
492
494
493
495
494
496
@fixture
@@ -683,6 +685,7 @@ def __init__(
683
685
self ,
684
686
request : FixtureRequest ,
685
687
tmp_path_factory : TempPathFactory ,
688
+ monkeypatch : MonkeyPatch ,
686
689
* ,
687
690
_ispytest : bool = False ,
688
691
) -> None :
@@ -706,7 +709,7 @@ def __init__(
706
709
self ._method = self ._request .config .getoption ("--runpytest" )
707
710
self ._test_tmproot = tmp_path_factory .mktemp (f"tmp-{ name } " , numbered = True )
708
711
709
- self ._monkeypatch = mp = MonkeyPatch ()
712
+ self ._monkeypatch = mp = monkeypatch
710
713
mp .setenv ("PYTEST_DEBUG_TEMPROOT" , str (self ._test_tmproot ))
711
714
# Ensure no unexpected caching via tox.
712
715
mp .delenv ("TOX_ENV_DIR" , raising = False )
@@ -738,7 +741,6 @@ def _finalize(self) -> None:
738
741
self ._sys_modules_snapshot .restore ()
739
742
self ._sys_path_snapshot .restore ()
740
743
self ._cwd_snapshot .restore ()
741
- self ._monkeypatch .undo ()
742
744
743
745
def __take_sys_modules_snapshot (self ) -> SysModulesSnapshot :
744
746
# Some zope modules used by twisted-related tests keep internal state
0 commit comments