summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdestin <101366538+kdestin@users.noreply.github.com>2023-04-05 15:15:27 -0400
committerGitHub <noreply@github.com>2023-04-05 12:15:27 -0700
commit1cf1848bf6eb94eff0c048f9883eba84d51e6870 (patch)
tree309f804017ab35bf8316bfa1093b25751114619d
parentb6b2443123121bd5d7eca89d6e372cc3bab8de4c (diff)
downloadtox-git-release-4.4.11.tar.gz
Allow plugins to set `tox_root` (#2978)release-4.4.11
-rw-r--r--docs/changelog/2966.bugfix.rst1
-rw-r--r--src/tox/provision.py9
-rw-r--r--tests/plugin/test_plugin.py28
3 files changed, 34 insertions, 4 deletions
diff --git a/docs/changelog/2966.bugfix.rst b/docs/changelog/2966.bugfix.rst
new file mode 100644
index 00000000..4e4b3d4b
--- /dev/null
+++ b/docs/changelog/2966.bugfix.rst
@@ -0,0 +1 @@
+Fixed an issue where a tox plugin couldn't change the value of ``tox_root``.
diff --git a/src/tox/provision.py b/src/tox/provision.py
index e67121bd..3428bc23 100644
--- a/src/tox/provision.py
+++ b/src/tox/provision.py
@@ -84,6 +84,11 @@ def provision(state: State) -> int | bool:
desc="Name of the virtual environment used to provision a tox.",
post_process=add_tox_requires_min_version,
)
+
+ from tox.plugin.manager import MANAGER
+
+ MANAGER.tox_add_core_config(state.conf.core, state)
+
requires: list[Requirement] = state.conf.core["requires"]
missing = _get_missing(requires)
@@ -100,10 +105,6 @@ def provision(state: State) -> int | bool:
state.conf.memory_seed_loaders[provision_tox_env].append(loader)
state.envs._mark_provision(bool(missing), provision_tox_env)
- from tox.plugin.manager import MANAGER
-
- MANAGER.tox_add_core_config(state.conf.core, state)
-
if not missing:
return False
diff --git a/tests/plugin/test_plugin.py b/tests/plugin/test_plugin.py
index 78a24540..0d00602f 100644
--- a/tests/plugin/test_plugin.py
+++ b/tests/plugin/test_plugin.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import logging
import os
import sys
+from pathlib import Path
from typing import Any
from unittest.mock import patch
@@ -102,6 +103,33 @@ def test_plugin_hooks_and_order(tox_project: ToxProjectCreator, mocker: MockerFi
assert result.out.splitlines() == expected, result.out
+@pytest.mark.parametrize(
+ "dir_name",
+ [
+ "tox_root",
+ "work_dir",
+ "temp_dir",
+ ],
+)
+def test_plugin_can_set_core_conf(
+ tox_project: ToxProjectCreator,
+ mocker: MockerFixture,
+ dir_name: str,
+ tmp_path: Path,
+) -> None:
+ @impl
+ def tox_add_core_config(core_conf: CoreConfigSet, state: State) -> None: # noqa: U100
+ core_conf.loaders.insert(0, MemoryLoader(**{dir_name: tmp_path}))
+
+ register_inline_plugin(mocker, tox_add_core_config)
+
+ project = tox_project({})
+ result = project.run("c")
+ result.assert_success()
+
+ assert result.state.conf.core[dir_name] == tmp_path
+
+
def test_plugin_can_read_env_list(tox_project: ToxProjectCreator, mocker: MockerFixture) -> None:
@impl
def tox_add_core_config(core_conf: CoreConfigSet, state: State) -> None: # noqa: U100