Remove/replace some unneeded usages of py.path
This commit is contained in:
@@ -21,12 +21,11 @@ from _pytest.pathlib import register_cleanup_lock_removal
|
||||
from _pytest.pathlib import rm_rf
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.tmpdir import get_user
|
||||
from _pytest.tmpdir import TempdirFactory
|
||||
from _pytest.tmpdir import TempPathFactory
|
||||
|
||||
|
||||
def test_tmpdir_fixture(pytester: Pytester) -> None:
|
||||
p = pytester.copy_example("tmpdir/tmpdir_fixture.py")
|
||||
def test_tmp_path_fixture(pytester: Pytester) -> None:
|
||||
p = pytester.copy_example("tmpdir/tmp_path_fixture.py")
|
||||
results = pytester.runpytest(p)
|
||||
results.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
@@ -47,18 +46,16 @@ class FakeConfig:
|
||||
return self
|
||||
|
||||
|
||||
class TestTempdirHandler:
|
||||
class TestTmpPathHandler:
|
||||
def test_mktemp(self, tmp_path):
|
||||
config = cast(Config, FakeConfig(tmp_path))
|
||||
t = TempdirFactory(
|
||||
TempPathFactory.from_config(config, _ispytest=True), _ispytest=True
|
||||
)
|
||||
t = TempPathFactory.from_config(config, _ispytest=True)
|
||||
tmp = t.mktemp("world")
|
||||
assert tmp.relto(t.getbasetemp()) == "world0"
|
||||
assert str(tmp.relative_to(t.getbasetemp())) == "world0"
|
||||
tmp = t.mktemp("this")
|
||||
assert tmp.relto(t.getbasetemp()).startswith("this")
|
||||
assert str(tmp.relative_to(t.getbasetemp())).startswith("this")
|
||||
tmp2 = t.mktemp("this")
|
||||
assert tmp2.relto(t.getbasetemp()).startswith("this")
|
||||
assert str(tmp2.relative_to(t.getbasetemp())).startswith("this")
|
||||
assert tmp2 != tmp
|
||||
|
||||
def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
|
||||
@@ -69,12 +66,12 @@ class TestTempdirHandler:
|
||||
assert t.getbasetemp().resolve() == (tmp_path / "hello").resolve()
|
||||
|
||||
|
||||
class TestConfigTmpdir:
|
||||
class TestConfigTmpPath:
|
||||
def test_getbasetemp_custom_removes_old(self, pytester: Pytester) -> None:
|
||||
mytemp = pytester.path.joinpath("xyz")
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
def test_1(tmpdir):
|
||||
def test_1(tmp_path):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
@@ -104,8 +101,8 @@ def test_mktemp(pytester: Pytester, basename: str, is_ok: bool) -> None:
|
||||
mytemp = pytester.mkdir("mytemp")
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
def test_abs_path(tmpdir_factory):
|
||||
tmpdir_factory.mktemp('{}', numbered=False)
|
||||
def test_abs_path(tmp_path_factory):
|
||||
tmp_path_factory.mktemp('{}', numbered=False)
|
||||
""".format(
|
||||
basename
|
||||
)
|
||||
@@ -157,44 +154,44 @@ def test_tmp_path_always_is_realpath(pytester: Pytester, monkeypatch) -> None:
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
def test_tmpdir_too_long_on_parametrization(pytester: Pytester) -> None:
|
||||
def test_tmp_path_too_long_on_parametrization(pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.mark.parametrize("arg", ["1"*1000])
|
||||
def test_some(arg, tmpdir):
|
||||
tmpdir.ensure("hello")
|
||||
def test_some(arg, tmp_path):
|
||||
tmp_path.joinpath("hello").touch()
|
||||
"""
|
||||
)
|
||||
reprec = pytester.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
def test_tmpdir_factory(pytester: Pytester) -> None:
|
||||
def test_tmp_path_factory(pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.fixture(scope='session')
|
||||
def session_dir(tmpdir_factory):
|
||||
return tmpdir_factory.mktemp('data', numbered=False)
|
||||
def session_dir(tmp_path_factory):
|
||||
return tmp_path_factory.mktemp('data', numbered=False)
|
||||
def test_some(session_dir):
|
||||
assert session_dir.isdir()
|
||||
assert session_dir.is_dir()
|
||||
"""
|
||||
)
|
||||
reprec = pytester.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
def test_tmpdir_fallback_tox_env(pytester: Pytester, monkeypatch) -> None:
|
||||
"""Test that tmpdir works even if environment variables required by getpass
|
||||
def test_tmp_path_fallback_tox_env(pytester: Pytester, monkeypatch) -> None:
|
||||
"""Test that tmp_path works even if environment variables required by getpass
|
||||
module are missing (#1010).
|
||||
"""
|
||||
monkeypatch.delenv("USER", raising=False)
|
||||
monkeypatch.delenv("USERNAME", raising=False)
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
def test_some(tmpdir):
|
||||
assert tmpdir.isdir()
|
||||
def test_some(tmp_path):
|
||||
assert tmp_path.is_dir()
|
||||
"""
|
||||
)
|
||||
reprec = pytester.inline_run()
|
||||
@@ -211,15 +208,15 @@ def break_getuser(monkeypatch):
|
||||
|
||||
@pytest.mark.usefixtures("break_getuser")
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
|
||||
def test_tmpdir_fallback_uid_not_found(pytester: Pytester) -> None:
|
||||
"""Test that tmpdir works even if the current process's user id does not
|
||||
def test_tmp_path_fallback_uid_not_found(pytester: Pytester) -> None:
|
||||
"""Test that tmp_path works even if the current process's user id does not
|
||||
correspond to a valid user.
|
||||
"""
|
||||
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
def test_some(tmpdir):
|
||||
assert tmpdir.isdir()
|
||||
def test_some(tmp_path):
|
||||
assert tmp_path.is_dir()
|
||||
"""
|
||||
)
|
||||
reprec = pytester.inline_run()
|
||||
|
||||
Reference in New Issue
Block a user