@@ -359,8 +359,8 @@ def LineMatcher_fixture(request: FixtureRequest) -> "Type[LineMatcher]":
359359
360360
361361@pytest .fixture
362- def testdir (request : FixtureRequest , tmpdir_factory ) -> "Testdir" :
363- return Testdir (request , tmpdir_factory )
362+ def testdir (request : FixtureRequest , tmpdir_factory , monkeypatch ) -> "Testdir" :
363+ return Testdir (request , tmpdir_factory , monkeypatch = monkeypatch )
364364
365365
366366@pytest .fixture
@@ -524,21 +524,26 @@ class Testdir:
524524 class TimeoutExpired (Exception ):
525525 pass
526526
527- def __init__ (self , request , tmpdir_factory ):
527+ def __init__ (
528+ self , request , tmpdir_factory , * , monkeypatch : Optional [MonkeyPatch ] = None
529+ ) -> None :
528530 self .request = request
529- self ._mod_collections = WeakKeyDictionary ()
531+ self ._mod_collections = WeakKeyDictionary () # type: ignore
530532 name = request .function .__name__
531533 self .tmpdir = tmpdir_factory .mktemp (name , numbered = True )
532534 self .test_tmproot = tmpdir_factory .mktemp ("tmp-" + name , numbered = True )
533- self .plugins = []
535+ self .plugins = [] # type: ignore
534536 self ._cwd_snapshot = CwdSnapshot ()
535537 self ._sys_path_snapshot = SysPathsSnapshot ()
536538 self ._sys_modules_snapshot = self .__take_sys_modules_snapshot ()
537539 self .chdir ()
538540 self .request .addfinalizer (self .finalize )
539541 self ._method = self .request .config .getoption ("--runpytest" )
540542
541- mp = self .monkeypatch = MonkeyPatch ()
543+ if monkeypatch is None :
544+ mp = self .monkeypatch = self .request .getfixturevalue ("monkeypatch" )
545+ else :
546+ mp = self .monkeypatch = monkeypatch
542547 mp .setenv ("PYTEST_DEBUG_TEMPROOT" , str (self .test_tmproot ))
543548 # Ensure no unexpected caching via tox.
544549 mp .delenv ("TOX_ENV_DIR" , raising = False )
0 commit comments