From 1cf1848bf6eb94eff0c048f9883eba84d51e6870 Mon Sep 17 00:00:00 2001 From: kdestin <101366538+kdestin@users.noreply.github.com> Date: Wed, 5 Apr 2023 15:15:27 -0400 Subject: Allow plugins to set `tox_root` (#2978) --- docs/changelog/2966.bugfix.rst | 1 + src/tox/provision.py | 9 +++++---- tests/plugin/test_plugin.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 docs/changelog/2966.bugfix.rst 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 -- cgit v1.2.1