Skip to content

Commit

Permalink
Merge pull request #9805 from pytest-dev/backport-9804-to-7.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored Mar 21, 2022
2 parents d9794ed + b55b7f1 commit 6461e2e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def test_global_file(self, pytester: Pytester) -> None:
for parent in col.listchain():
assert parent.config is config

def test_pkgfile(self, pytester: Pytester) -> None:
def test_pkgfile(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
"""Verify nesting when a module is within a package.
The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
Session's parent should always be None.
Expand All @@ -660,7 +660,9 @@ def test_pkgfile(self, pytester: Pytester) -> None:
subdir = tmp_path.joinpath("subdir")
x = ensure_file(subdir / "x.py")
ensure_file(subdir / "__init__.py")
config = pytester.parseconfigure(x)
with monkeypatch.context() as mp:
mp.chdir(subdir)
config = pytester.parseconfigure(x)
col = pytester.getnode(config, x)
assert col is not None
assert col.name == "x.py"
Expand Down Expand Up @@ -1221,7 +1223,9 @@ def test_collect_pyargs_with_testpaths(
)
)
monkeypatch.setenv("PYTHONPATH", str(pytester.path), prepend=os.pathsep)
result = pytester.runpytest_subprocess()
with monkeypatch.context() as mp:
mp.chdir(root)
result = pytester.runpytest_subprocess()
result.stdout.fnmatch_lines(["*1 passed in*"])


Expand Down

0 comments on commit 6461e2e

Please sign in to comment.