Skip to content

Commit 1cf1848

Browse files
authored
Allow plugins to set tox_root (#2978)
1 parent b6b2443 commit 1cf1848

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

docs/changelog/2966.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed an issue where a tox plugin couldn't change the value of ``tox_root``.

src/tox/provision.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def add_tox_requires_min_version(reqs: list[Requirement]) -> list[Requirement]:
8484
desc="Name of the virtual environment used to provision a tox.",
8585
post_process=add_tox_requires_min_version,
8686
)
87+
88+
from tox.plugin.manager import MANAGER
89+
90+
MANAGER.tox_add_core_config(state.conf.core, state)
91+
8792
requires: list[Requirement] = state.conf.core["requires"]
8893
missing = _get_missing(requires)
8994

@@ -100,10 +105,6 @@ def add_tox_requires_min_version(reqs: list[Requirement]) -> list[Requirement]:
100105
state.conf.memory_seed_loaders[provision_tox_env].append(loader)
101106
state.envs._mark_provision(bool(missing), provision_tox_env)
102107

103-
from tox.plugin.manager import MANAGER
104-
105-
MANAGER.tox_add_core_config(state.conf.core, state)
106-
107108
if not missing:
108109
return False
109110

tests/plugin/test_plugin.py

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import sys
6+
from pathlib import Path
67
from typing import Any
78
from unittest.mock import patch
89

@@ -102,6 +103,33 @@ def tox_env_teardown(tox_env: ToxEnv) -> None:
102103
assert result.out.splitlines() == expected, result.out
103104

104105

106+
@pytest.mark.parametrize(
107+
"dir_name",
108+
[
109+
"tox_root",
110+
"work_dir",
111+
"temp_dir",
112+
],
113+
)
114+
def test_plugin_can_set_core_conf(
115+
tox_project: ToxProjectCreator,
116+
mocker: MockerFixture,
117+
dir_name: str,
118+
tmp_path: Path,
119+
) -> None:
120+
@impl
121+
def tox_add_core_config(core_conf: CoreConfigSet, state: State) -> None: # noqa: U100
122+
core_conf.loaders.insert(0, MemoryLoader(**{dir_name: tmp_path}))
123+
124+
register_inline_plugin(mocker, tox_add_core_config)
125+
126+
project = tox_project({})
127+
result = project.run("c")
128+
result.assert_success()
129+
130+
assert result.state.conf.core[dir_name] == tmp_path
131+
132+
105133
def test_plugin_can_read_env_list(tox_project: ToxProjectCreator, mocker: MockerFixture) -> None:
106134
@impl
107135
def tox_add_core_config(core_conf: CoreConfigSet, state: State) -> None: # noqa: U100

0 commit comments

Comments
 (0)