diff --git a/docs/changelog/2966.bugfix.rst b/docs/changelog/2966.bugfix.rst new file mode 100644 index 000000000..4e4b3d4b5 --- /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 e67121bd8..3428bc238 100644 --- a/src/tox/provision.py +++ b/src/tox/provision.py @@ -84,6 +84,11 @@ def add_tox_requires_min_version(reqs: list[Requirement]) -> list[Requirement]: 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 add_tox_requires_min_version(reqs: list[Requirement]) -> list[Requirement]: 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 78a245400..0d00602f9 100644 --- a/tests/plugin/test_plugin.py +++ b/tests/plugin/test_plugin.py @@ -3,6 +3,7 @@ import logging import os import sys +from pathlib import Path from typing import Any from unittest.mock import patch @@ -102,6 +103,33 @@ def tox_env_teardown(tox_env: ToxEnv) -> None: 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