@@ -359,8 +359,8 @@ def LineMatcher_fixture(request: FixtureRequest) -> "Type[LineMatcher]":
359
359
360
360
361
361
@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 )
364
364
365
365
366
366
@pytest .fixture
@@ -524,21 +524,26 @@ class Testdir:
524
524
class TimeoutExpired (Exception ):
525
525
pass
526
526
527
- def __init__ (self , request , tmpdir_factory ):
527
+ def __init__ (
528
+ self , request , tmpdir_factory , * , monkeypatch : Optional [MonkeyPatch ] = None
529
+ ) -> None :
528
530
self .request = request
529
- self ._mod_collections = WeakKeyDictionary ()
531
+ self ._mod_collections = WeakKeyDictionary () # type: ignore
530
532
name = request .function .__name__
531
533
self .tmpdir = tmpdir_factory .mktemp (name , numbered = True )
532
534
self .test_tmproot = tmpdir_factory .mktemp ("tmp-" + name , numbered = True )
533
- self .plugins = []
535
+ self .plugins = [] # type: ignore
534
536
self ._cwd_snapshot = CwdSnapshot ()
535
537
self ._sys_path_snapshot = SysPathsSnapshot ()
536
538
self ._sys_modules_snapshot = self .__take_sys_modules_snapshot ()
537
539
self .chdir ()
538
540
self .request .addfinalizer (self .finalize )
539
541
self ._method = self .request .config .getoption ("--runpytest" )
540
542
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
542
547
mp .setenv ("PYTEST_DEBUG_TEMPROOT" , str (self .test_tmproot ))
543
548
# Ensure no unexpected caching via tox.
544
549
mp .delenv ("TOX_ENV_DIR" , raising = False )
0 commit comments