Skip to content

Commit 0dd1e5b

Browse files
committed
pathlib: inline ensure_reset_dir()
This is only used in TempPathFactory.getbasetemp(). We'll be wanting further control/care there, so move it into there.
1 parent 78122a5 commit 0dd1e5b

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/_pytest/pathlib.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ def get_lock_path(path: _AnyPurePath) -> _AnyPurePath:
6262
return path.joinpath(".lock")
6363

6464

65-
def ensure_reset_dir(path: Path) -> None:
66-
"""Ensure the given path is an empty directory."""
67-
if path.exists():
68-
rm_rf(path)
69-
path.mkdir()
70-
71-
7265
def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool:
7366
"""Handle known read-only errors during rmtree.
7467

src/_pytest/tmpdir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import attr
99

10-
from .pathlib import ensure_reset_dir
1110
from .pathlib import LOCK_TIMEOUT
1211
from .pathlib import make_numbered_dir
1312
from .pathlib import make_numbered_dir_with_cleanup
13+
from .pathlib import rm_rf
1414
from _pytest.compat import final
1515
from _pytest.compat import LEGACY_PATH
1616
from _pytest.compat import legacy_path
@@ -107,7 +107,9 @@ def getbasetemp(self) -> Path:
107107

108108
if self._given_basetemp is not None:
109109
basetemp = self._given_basetemp
110-
ensure_reset_dir(basetemp)
110+
if basetemp.exists():
111+
rm_rf(basetemp)
112+
basetemp.mkdir()
111113
basetemp = basetemp.resolve()
112114
else:
113115
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")

0 commit comments

Comments
 (0)