Skip to content

Commit

Permalink
pathlib: inline ensure_reset_dir()
Browse files Browse the repository at this point in the history
This is only used in TempPathFactory.getbasetemp(). We'll be wanting
further control/care there, so move it into there.
  • Loading branch information
bluetech committed Apr 3, 2021
1 parent 02fdbe2 commit 93dbae2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ def get_lock_path(path: _AnyPurePath) -> _AnyPurePath:
return path.joinpath(".lock")


def ensure_reset_dir(path: Path) -> None:
"""Ensure the given path is an empty directory."""
if path.exists():
rm_rf(path)
path.mkdir()


def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool:
"""Handle known read-only errors during rmtree.
Expand Down
6 changes: 4 additions & 2 deletions src/_pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import attr
import py

from .pathlib import ensure_reset_dir
from .pathlib import LOCK_TIMEOUT
from .pathlib import make_numbered_dir
from .pathlib import make_numbered_dir_with_cleanup
from .pathlib import rm_rf
from _pytest.compat import final
from _pytest.config import Config
from _pytest.deprecated import check_ispytest
Expand Down Expand Up @@ -103,7 +103,9 @@ def getbasetemp(self) -> Path:

if self._given_basetemp is not None:
basetemp = self._given_basetemp
ensure_reset_dir(basetemp)
if basetemp.exists():
rm_rf(basetemp)
basetemp.mkdir()
basetemp = basetemp.resolve()
else:
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")
Expand Down

0 comments on commit 93dbae2

Please sign in to comment.