diff --git a/docs/changelog/2770.bugfix.rst b/docs/changelog/2770.bugfix.rst new file mode 100644 index 000000000..f08d2d5fe --- /dev/null +++ b/docs/changelog/2770.bugfix.rst @@ -0,0 +1 @@ +Create temp_dir if not exists - by :user:`q0w`. diff --git a/docs/config.rst b/docs/config.rst index dcfaa5025..ed9e8d352 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -172,7 +172,7 @@ Core .. conf:: :keys: temp_dir - :default: {tox_root}/.temp + :default: {tox_root}/.tmp Directory where to put tox temporary files. For example: we create a hard link (if possible, otherwise new copy) in this directory for the project package. This ensures tox works correctly when having parallel runs (as each session diff --git a/src/tox/tox_env/api.py b/src/tox/tox_env/api.py index e87710d5d..98c4501a9 100644 --- a/src/tox/tox_env/api.py +++ b/src/tox/tox_env/api.py @@ -288,6 +288,7 @@ def _setup_env(self) -> None: if eq is False and old is not None: # pragma: no branch # recreate if already created and not equals raise Recreate(f"env type changed from {old} to {conf}") self._handle_env_tmp_dir() + self._handle_core_tmp_dir() def _setup_with_env(self) -> None: # noqa: B027 # empty abstract base class pass @@ -303,6 +304,9 @@ def _handle_env_tmp_dir(self) -> None: ensure_empty_dir(env_tmp_dir) env_tmp_dir.mkdir(parents=True, exist_ok=True) + def _handle_core_tmp_dir(self) -> None: + self.core["temp_dir"].mkdir(parents=True, exist_ok=True) + def _clean(self, transitive: bool = False) -> None: # noqa: U100 if self._run_state["clean"]: # pragma: no branch return # pragma: no cover diff --git a/tests/tox_env/test_api.py b/tests/tox_env/test_api.py new file mode 100644 index 000000000..310e7fb5b --- /dev/null +++ b/tests/tox_env/test_api.py @@ -0,0 +1,18 @@ +from pathlib import Path + +from tox.pytest import ToxProjectCreator + + +def test_ensure_temp_dir_exists(tox_project: ToxProjectCreator) -> None: + ini = "[testenv]\ncommands=python -c 'import os; os.path.exists(r\"{temp_dir}\")'" + project = tox_project({"tox.ini": ini}) + result = project.run() + result.assert_success() + + +def test_dont_cleanup_temp_dir(tox_project: ToxProjectCreator, tmp_path: Path) -> None: + (tmp_path / "foo" / "bar").mkdir(parents=True) + project = tox_project({"tox.ini": "[tox]\ntemp_dir=foo"}) + result = project.run() + result.assert_success() + assert (tmp_path / "foo" / "bar").exists()