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:
parent
78122a5304
commit
0dd1e5b4f4
|
@ -62,13 +62,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.
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ from typing import Optional
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
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.compat import LEGACY_PATH
|
from _pytest.compat import LEGACY_PATH
|
||||||
from _pytest.compat import legacy_path
|
from _pytest.compat import legacy_path
|
||||||
|
@ -107,7 +107,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")
|
||||||
|
|
Loading…
Reference in New Issue