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.
This commit is contained in:
Ran Benita 2021-03-06 16:22:59 +02:00
parent 02fdbe2e76
commit 93dbae24e1
2 changed files with 4 additions and 9 deletions

View File

@ -64,13 +64,6 @@ def get_lock_path(path: _AnyPurePath) -> _AnyPurePath:
return path.joinpath(".lock") 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: def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool:
"""Handle known read-only errors during rmtree. """Handle known read-only errors during rmtree.

View File

@ -8,10 +8,10 @@ from typing import Optional
import attr import attr
import py import py
from .pathlib import ensure_reset_dir
from .pathlib import LOCK_TIMEOUT from .pathlib import LOCK_TIMEOUT
from .pathlib import make_numbered_dir from .pathlib import make_numbered_dir
from .pathlib import make_numbered_dir_with_cleanup from .pathlib import make_numbered_dir_with_cleanup
from .pathlib import rm_rf
from _pytest.compat import final from _pytest.compat import final
from _pytest.config import Config from _pytest.config import Config
from _pytest.deprecated import check_ispytest from _pytest.deprecated import check_ispytest
@ -103,7 +103,9 @@ class TempPathFactory:
if self._given_basetemp is not None: if self._given_basetemp is not None:
basetemp = self._given_basetemp basetemp = self._given_basetemp
ensure_reset_dir(basetemp) if basetemp.exists():
rm_rf(basetemp)
basetemp.mkdir()
basetemp = basetemp.resolve() basetemp = basetemp.resolve()
else: else:
from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT")