summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorq0w <43147888+q0w@users.noreply.github.com>2022-12-28 18:49:04 +0300
committerGitHub <noreply@github.com>2022-12-28 07:49:04 -0800
commit39dd2b6e834a53441ad1207ca67bf748f887b066 (patch)
treed24159aad3b09f885954950f525e9b96f8b32cbc
parentc850edffe0a37118f39019a06d7702963eaf3d6d (diff)
downloadtox-git-39dd2b6e834a53441ad1207ca67bf748f887b066.tar.gz
Create temp_dir if not exists (#2781)
Closes https://github.com/tox-dev/tox/issues/2770
-rw-r--r--docs/changelog/2770.bugfix.rst1
-rw-r--r--docs/config.rst2
-rw-r--r--src/tox/tox_env/api.py4
-rw-r--r--tests/tox_env/test_api.py18
4 files changed, 24 insertions, 1 deletions
diff --git a/docs/changelog/2770.bugfix.rst b/docs/changelog/2770.bugfix.rst
new file mode 100644
index 00000000..f08d2d5f
--- /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 dcfaa502..ed9e8d35 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 e87710d5..98c4501a 100644
--- a/src/tox/tox_env/api.py
+++ b/src/tox/tox_env/api.py
@@ -288,6 +288,7 @@ class ToxEnv(ABC):
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 @@ class ToxEnv(ABC):
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 00000000..310e7fb5
--- /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()