Skip to content

Commit a1a605a

Browse files
committed
Move Cache.makedir to legacypath plugin
1 parent 5e883f5 commit a1a605a

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/_pytest/cacheprovider.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from _pytest import nodes
2121
from _pytest._io import TerminalWriter
2222
from _pytest.compat import final
23-
from _pytest.compat import LEGACY_PATH
24-
from _pytest.compat import legacy_path
2523
from _pytest.config import Config
2624
from _pytest.config import ExitCode
2725
from _pytest.config import hookimpl
@@ -142,13 +140,6 @@ def mkdir(self, name: str) -> Path:
142140
res.mkdir(exist_ok=True, parents=True)
143141
return res
144142

145-
def makedir(self, name: str) -> LEGACY_PATH:
146-
"""Return a directory path object with the given name.
147-
148-
Same as :func:`mkdir`, but returns a legacy py path instance.
149-
"""
150-
return legacy_path(self.mkdir(name))
151-
152143
def _getvaluepath(self, key: str) -> Path:
153144
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))
154145

src/_pytest/legacypath.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ def tmpdir(tmp_path: Path) -> LEGACY_PATH:
307307
return legacy_path(tmp_path)
308308

309309

310+
def Cache_makedir(self: pytest.Cache, name: str) -> LEGACY_PATH:
311+
"""Return a directory path object with the given name.
312+
313+
Same as :func:`mkdir`, but returns a legacy py path instance.
314+
"""
315+
return legacy_path(self.mkdir(name))
316+
317+
310318
def pytest_configure(config: pytest.Config) -> None:
311319
mp = pytest.MonkeyPatch()
312320
config.add_cleanup(mp.undo)
@@ -324,3 +332,6 @@ def pytest_configure(config: pytest.Config) -> None:
324332
else:
325333
_tmpdirhandler = TempdirFactory(tmp_path_factory, _ispytest=True)
326334
mp.setattr(config, "_tmpdirhandler", _tmpdirhandler, raising=False)
335+
336+
# Add Cache.makedir().
337+
mp.setattr(pytest.Cache, "makedir", Cache_makedir, raising=False)

testing/test_legacypath.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ def test_1(tmpdir):
6767
)
6868
result = pytester.runpytest("-s", p, "--basetemp=%s/bt" % linktemp)
6969
assert not result.ret
70+
71+
72+
def test_cache_makedir(cache: pytest.Cache) -> None:
73+
dir = cache.makedir("foo") # type: ignore[attr-defined]
74+
assert dir.exists()
75+
dir.remove()

0 commit comments

Comments
 (0)