Skip to content

Commit

Permalink
Allow plugins to set tox_root (#2978)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdestin authored Apr 5, 2023
1 parent b6b2443 commit 1cf1848
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2966.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where a tox plugin couldn't change the value of ``tox_root``.
9 changes: 5 additions & 4 deletions src/tox/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
28 changes: 28 additions & 0 deletions tests/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
from pathlib import Path
from typing import Any
from unittest.mock import patch

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1cf1848

Please sign in to comment.