Skip to content

Commit 93dbae2

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 02fdbe2 commit 93dbae2

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/_pytest/pathlib.py

-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ def get_lock_path(path: _AnyPurePath) -> _AnyPurePath:
6464
return path.joinpath(".lock")
6565

6666

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

src/_pytest/tmpdir.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import attr
99
import py
1010

11-
from .pathlib import ensure_reset_dir
1211
from .pathlib import LOCK_TIMEOUT
1312
from .pathlib import make_numbered_dir
1413
from .pathlib import make_numbered_dir_with_cleanup
14+
from .pathlib import rm_rf
1515
from _pytest.compat import final
1616
from _pytest.config import Config
1717
from _pytest.deprecated import check_ispytest
@@ -103,7 +103,9 @@ def getbasetemp(self) -> Path:
103103

104104
if self._given_basetemp is not None:
105105
basetemp = self._given_basetemp
106-
ensure_reset_dir(basetemp)
106+
if basetemp.exists():
107+
rm_rf(basetemp)
108+
basetemp.mkdir()
107109
basetemp = basetemp.resolve()
108110
else:
109111
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")

0 commit comments

Comments
 (0)