Move Cache.makedir to legacypath plugin
This commit is contained in:
parent
5e883f5195
commit
a1a605a63e
|
@ -20,8 +20,6 @@ from .reports import CollectReport
|
|||
from _pytest import nodes
|
||||
from _pytest._io import TerminalWriter
|
||||
from _pytest.compat import final
|
||||
from _pytest.compat import LEGACY_PATH
|
||||
from _pytest.compat import legacy_path
|
||||
from _pytest.config import Config
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.config import hookimpl
|
||||
|
@ -142,13 +140,6 @@ class Cache:
|
|||
res.mkdir(exist_ok=True, parents=True)
|
||||
return res
|
||||
|
||||
def makedir(self, name: str) -> LEGACY_PATH:
|
||||
"""Return a directory path object with the given name.
|
||||
|
||||
Same as :func:`mkdir`, but returns a legacy py path instance.
|
||||
"""
|
||||
return legacy_path(self.mkdir(name))
|
||||
|
||||
def _getvaluepath(self, key: str) -> Path:
|
||||
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))
|
||||
|
||||
|
|
|
@ -307,6 +307,14 @@ def tmpdir(tmp_path: Path) -> LEGACY_PATH:
|
|||
return legacy_path(tmp_path)
|
||||
|
||||
|
||||
def Cache_makedir(self: pytest.Cache, name: str) -> LEGACY_PATH:
|
||||
"""Return a directory path object with the given name.
|
||||
|
||||
Same as :func:`mkdir`, but returns a legacy py path instance.
|
||||
"""
|
||||
return legacy_path(self.mkdir(name))
|
||||
|
||||
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
mp = pytest.MonkeyPatch()
|
||||
config.add_cleanup(mp.undo)
|
||||
|
@ -324,3 +332,6 @@ def pytest_configure(config: pytest.Config) -> None:
|
|||
else:
|
||||
_tmpdirhandler = TempdirFactory(tmp_path_factory, _ispytest=True)
|
||||
mp.setattr(config, "_tmpdirhandler", _tmpdirhandler, raising=False)
|
||||
|
||||
# Add Cache.makedir().
|
||||
mp.setattr(pytest.Cache, "makedir", Cache_makedir, raising=False)
|
||||
|
|
|
@ -67,3 +67,9 @@ def test_tmpdir_always_is_realpath(pytester: pytest.Pytester) -> None:
|
|||
)
|
||||
result = pytester.runpytest("-s", p, "--basetemp=%s/bt" % linktemp)
|
||||
assert not result.ret
|
||||
|
||||
|
||||
def test_cache_makedir(cache: pytest.Cache) -> None:
|
||||
dir = cache.makedir("foo") # type: ignore[attr-defined]
|
||||
assert dir.exists()
|
||||
dir.remove()
|
||||
|
|
Loading…
Reference in New Issue