Skip to content

Commit 6461e2e

Browse files
authored
Merge pull request #9805 from pytest-dev/backport-9804-to-7.1.x
2 parents d9794ed + b55b7f1 commit 6461e2e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

testing/test_collection.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def test_global_file(self, pytester: Pytester) -> None:
651651
for parent in col.listchain():
652652
assert parent.config is config
653653

654-
def test_pkgfile(self, pytester: Pytester) -> None:
654+
def test_pkgfile(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
655655
"""Verify nesting when a module is within a package.
656656
The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
657657
Session's parent should always be None.
@@ -660,7 +660,9 @@ def test_pkgfile(self, pytester: Pytester) -> None:
660660
subdir = tmp_path.joinpath("subdir")
661661
x = ensure_file(subdir / "x.py")
662662
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)
664666
col = pytester.getnode(config, x)
665667
assert col is not None
666668
assert col.name == "x.py"
@@ -1221,7 +1223,9 @@ def test_collect_pyargs_with_testpaths(
12211223
)
12221224
)
12231225
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()
12251229
result.stdout.fnmatch_lines(["*1 passed in*"])
12261230

12271231

0 commit comments

Comments
 (0)