Merge pull request #9804 from nicoddemus/311-cwd-tests

This commit is contained in:
Bruno Oliveira 2022-03-21 13:11:51 -03:00 committed by GitHub
commit 250a0344ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -651,7 +651,7 @@ class Test_getinitialnodes:
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.
@ -660,7 +660,9 @@ class Test_getinitialnodes:
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"
@ -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*"])