Skip to content

Commit 39dd2b6

Browse files
authored
Create temp_dir if not exists (#2781)
Closes #2770
1 parent c850edf commit 39dd2b6

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

docs/changelog/2770.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create temp_dir if not exists - by :user:`q0w`.

docs/config.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Core
172172

173173
.. conf::
174174
:keys: temp_dir
175-
:default: {tox_root}/.temp
175+
:default: {tox_root}/.tmp
176176

177177
Directory where to put tox temporary files. For example: we create a hard link (if possible, otherwise new copy) in
178178
this directory for the project package. This ensures tox works correctly when having parallel runs (as each session

src/tox/tox_env/api.py

+4
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def _setup_env(self) -> None:
288288
if eq is False and old is not None: # pragma: no branch # recreate if already created and not equals
289289
raise Recreate(f"env type changed from {old} to {conf}")
290290
self._handle_env_tmp_dir()
291+
self._handle_core_tmp_dir()
291292

292293
def _setup_with_env(self) -> None: # noqa: B027 # empty abstract base class
293294
pass
@@ -303,6 +304,9 @@ def _handle_env_tmp_dir(self) -> None:
303304
ensure_empty_dir(env_tmp_dir)
304305
env_tmp_dir.mkdir(parents=True, exist_ok=True)
305306

307+
def _handle_core_tmp_dir(self) -> None:
308+
self.core["temp_dir"].mkdir(parents=True, exist_ok=True)
309+
306310
def _clean(self, transitive: bool = False) -> None: # noqa: U100
307311
if self._run_state["clean"]: # pragma: no branch
308312
return # pragma: no cover

tests/tox_env/test_api.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pathlib import Path
2+
3+
from tox.pytest import ToxProjectCreator
4+
5+
6+
def test_ensure_temp_dir_exists(tox_project: ToxProjectCreator) -> None:
7+
ini = "[testenv]\ncommands=python -c 'import os; os.path.exists(r\"{temp_dir}\")'"
8+
project = tox_project({"tox.ini": ini})
9+
result = project.run()
10+
result.assert_success()
11+
12+
13+
def test_dont_cleanup_temp_dir(tox_project: ToxProjectCreator, tmp_path: Path) -> None:
14+
(tmp_path / "foo" / "bar").mkdir(parents=True)
15+
project = tox_project({"tox.ini": "[tox]\ntemp_dir=foo"})
16+
result = project.run()
17+
result.assert_success()
18+
assert (tmp_path / "foo" / "bar").exists()

0 commit comments

Comments
 (0)