Fix other tests that do not restore CWD
This commit is contained in:
parent
8576b61da3
commit
5ffbbef0a5
|
@ -618,6 +618,7 @@ class TestLocalPath(CommonFSTests):
|
|||
|
||||
@skiponwin32
|
||||
def test_chdir_gone(self, path1):
|
||||
original_cwd = os.getcwd()
|
||||
p = path1.ensure("dir_to_be_removed", dir=1)
|
||||
p.chdir()
|
||||
p.remove()
|
||||
|
@ -628,15 +629,18 @@ class TestLocalPath(CommonFSTests):
|
|||
with pytest.raises(error.ENOENT):
|
||||
with p.as_cwd():
|
||||
raise NotImplementedError
|
||||
os.chdir(original_cwd)
|
||||
|
||||
@skiponwin32
|
||||
def test_chdir_gone_in_as_cwd(self, path1):
|
||||
original_cwd = os.getcwd()
|
||||
p = path1.ensure("dir_to_be_removed", dir=1)
|
||||
p.chdir()
|
||||
p.remove()
|
||||
|
||||
with path1.as_cwd() as old:
|
||||
assert old is None
|
||||
os.chdir(original_cwd)
|
||||
|
||||
def test_as_cwd(self, path1):
|
||||
dir = path1.ensure("subdir", dir=1)
|
||||
|
|
|
@ -6,6 +6,7 @@ import types
|
|||
|
||||
import pytest
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from _pytest.pathlib import symlink_or_skip
|
||||
from _pytest.pytester import Pytester
|
||||
|
||||
|
@ -651,7 +652,7 @@ class TestInvocationVariants:
|
|||
result.stderr.fnmatch_lines(["*not*found*test_missing*"])
|
||||
|
||||
def test_cmdline_python_namespace_package(
|
||||
self, pytester: Pytester, monkeypatch
|
||||
self, pytester: Pytester, monkeypatch: MonkeyPatch
|
||||
) -> None:
|
||||
"""Test --pyargs option with namespace packages (#1567).
|
||||
|
||||
|
@ -731,6 +732,7 @@ class TestInvocationVariants:
|
|||
result.stdout.fnmatch_lines(
|
||||
["*test_world.py::test_other*PASSED*", "*1 passed*"]
|
||||
)
|
||||
monkeypatch.undo()
|
||||
|
||||
def test_invoke_test_and_doctestmodules(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
|
|
|
@ -67,15 +67,14 @@ class FilesCompleter:
|
|||
|
||||
class TestArgComplete:
|
||||
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
|
||||
def test_compare_with_compgen(
|
||||
self, tmp_path: Path, monkeypatch: MonkeyPatch
|
||||
) -> None:
|
||||
def test_compare_with_compgen(self, tmp_path: Path) -> None:
|
||||
from _pytest._argcomplete import FastFilesCompleter
|
||||
|
||||
ffc = FastFilesCompleter()
|
||||
fc = FilesCompleter()
|
||||
|
||||
monkeypatch.chdir(tmp_path)
|
||||
with MonkeyPatch.context() as mp:
|
||||
mp.chdir(tmp_path)
|
||||
|
||||
assert equal_with_bash("", ffc, fc, out=sys.stdout)
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ class TestCollectFS:
|
|||
rec = pytester.inline_run("xyz123/test_2.py")
|
||||
rec.assertoutcome(failed=1)
|
||||
|
||||
def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
||||
def test_testpaths_ini(self, pytester: Pytester) -> None:
|
||||
pytester.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
|
@ -275,8 +275,9 @@ class TestCollectFS:
|
|||
|
||||
# changing cwd to each subdirectory and running pytest without
|
||||
# arguments collects the tests in that directory normally
|
||||
with MonkeyPatch.context() as mp:
|
||||
for dirname in ("a", "b", "c"):
|
||||
monkeypatch.chdir(pytester.path.joinpath(dirname))
|
||||
mp.chdir(pytester.path.joinpath(dirname))
|
||||
items, reprec = pytester.inline_genitems()
|
||||
assert [x.name for x in items] == ["test_%s" % dirname]
|
||||
|
||||
|
@ -660,7 +661,7 @@ class Test_getinitialnodes:
|
|||
for parent in col.listchain():
|
||||
assert parent.config is config
|
||||
|
||||
def test_pkgfile(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
||||
def test_pkgfile(self, pytester: Pytester) -> 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.
|
||||
|
@ -669,7 +670,7 @@ class Test_getinitialnodes:
|
|||
subdir = tmp_path.joinpath("subdir")
|
||||
x = ensure_file(subdir / "x.py")
|
||||
ensure_file(subdir / "__init__.py")
|
||||
with monkeypatch.context() as mp:
|
||||
with MonkeyPatch.context() as mp:
|
||||
mp.chdir(subdir)
|
||||
config = pytester.parseconfigure(x)
|
||||
col = pytester.getnode(config, x)
|
||||
|
|
Loading…
Reference in New Issue