Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to set tox_root #2978

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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