@@ -651,7 +651,7 @@ def test_global_file(self, pytester: Pytester) -> None:
651
651
for parent in col .listchain ():
652
652
assert parent .config is config
653
653
654
- def test_pkgfile (self , pytester : Pytester ) -> None :
654
+ def test_pkgfile (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
655
655
"""Verify nesting when a module is within a package.
656
656
The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
657
657
Session's parent should always be None.
@@ -660,7 +660,9 @@ def test_pkgfile(self, pytester: Pytester) -> None:
660
660
subdir = tmp_path .joinpath ("subdir" )
661
661
x = ensure_file (subdir / "x.py" )
662
662
ensure_file (subdir / "__init__.py" )
663
- config = pytester .parseconfigure (x )
663
+ with monkeypatch .context () as mp :
664
+ mp .chdir (subdir )
665
+ config = pytester .parseconfigure (x )
664
666
col = pytester .getnode (config , x )
665
667
assert col is not None
666
668
assert col .name == "x.py"
@@ -1221,7 +1223,9 @@ def test_collect_pyargs_with_testpaths(
1221
1223
)
1222
1224
)
1223
1225
monkeypatch .setenv ("PYTHONPATH" , str (pytester .path ), prepend = os .pathsep )
1224
- result = pytester .runpytest_subprocess ()
1226
+ with monkeypatch .context () as mp :
1227
+ mp .chdir (root )
1228
+ result = pytester .runpytest_subprocess ()
1225
1229
result .stdout .fnmatch_lines (["*1 passed in*" ])
1226
1230
1227
1231
0 commit comments