Skip to content

Commit ed39bd7

Browse files
authored
rename TOX_CONFIG_FILE to TOX_USER_CONFIG_FILE (#2896)
Fix #2890
1 parent b654be7 commit ed39bd7

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

docs/changelog/2890.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Allow the user configuration file (default ``<appdir>/tox/config.ini``) to be overridden via the
2+
``TOX_USER_CONFIG_FILE`` environment variable. Previously tox was looking at the ``TOX_CONFIG_FILE`` to override the
3+
user configuration, however that environment variable is already used to override the main configuration - by
4+
:user:`masenf`.

docs/config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ User configuration
789789

790790
tox allows creation of user level config-file to modify default values of the CLI commands.
791791
It is located in the OS-specific user config directory under ``tox/config.ini`` path, see ``tox --help`` output for exact location.
792-
It can be changed via ``TOX_CONFIG_FILE`` environment variable.
792+
It can be changed via ``TOX_USER_CONFIG_FILE`` environment variable.
793793
Example configuration:
794794

795795
.. code-block:: ini

src/tox/config/cli/ini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class IniConfig:
22-
TOX_CONFIG_FILE_ENV_VAR = "TOX_CONFIG_FILE"
22+
TOX_CONFIG_FILE_ENV_VAR = "TOX_USER_CONFIG_FILE"
2323
STATE = {None: "failed to parse", True: "active", False: "missing"}
2424

2525
def __init__(self) -> None:

tests/config/cli/test_cli_ini.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def exhaustive_ini(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path:
4444
""",
4545
),
4646
)
47-
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
47+
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
4848
return to
4949

5050

@@ -58,7 +58,7 @@ def test_ini_empty(
5858
content: str,
5959
) -> None:
6060
to = tmp_path / "tox.ini"
61-
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
61+
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
6262
to.write_text(content)
6363
mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path()))
6464
options = get_options("r")
@@ -73,7 +73,7 @@ def test_ini_empty(
7373

7474

7575
@pytest.fixture()
76-
def default_options(tmp_path: Path) -> dict[str, Any]:
76+
def default_options() -> dict[str, Any]:
7777
return {
7878
"colored": "no",
7979
"command": "r",
@@ -97,15 +97,16 @@ def default_options(tmp_path: Path) -> dict[str, Any]:
9797
"verbose": 2,
9898
"work_dir": None,
9999
"root_dir": None,
100-
"config_file": (tmp_path / "tox.ini").absolute(),
100+
"config_file": None,
101101
"factors": [],
102102
"labels": [],
103103
"exit_and_dump_after": 0,
104104
"skip_env": "",
105105
}
106106

107107

108-
def test_ini_exhaustive_parallel_values(exhaustive_ini: Path, core_handlers: dict[str, Callable[[State], int]]) -> None:
108+
@pytest.mark.usefixtures("exhaustive_ini")
109+
def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State], int]]) -> None:
109110
options = get_options("p")
110111
assert vars(options.parsed) == {
111112
"colored": "yes",
@@ -133,7 +134,7 @@ def test_ini_exhaustive_parallel_values(exhaustive_ini: Path, core_handlers: dic
133134
"verbose": 5,
134135
"work_dir": None,
135136
"root_dir": None,
136-
"config_file": exhaustive_ini,
137+
"config_file": None,
137138
"factors": [],
138139
"labels": [],
139140
"exit_and_dump_after": 0,
@@ -149,7 +150,7 @@ def test_ini_help(exhaustive_ini: Path, capsys: CaptureFixture) -> None:
149150
assert context.value.code == 0
150151
out, err = capsys.readouterr()
151152
assert not err
152-
assert f"config file '{exhaustive_ini}' active (changed via env var TOX_CONFIG_FILE)"
153+
assert f"config file '{exhaustive_ini}' active (changed via env var TOX_USER_CONFIG_FILE)"
153154

154155

155156
def test_bad_cli_ini(
@@ -161,15 +162,14 @@ def test_bad_cli_ini(
161162
) -> None:
162163
mocker.patch("tox.config.cli.parse.discover_source", return_value=mocker.MagicMock(path=Path()))
163164
caplog.set_level(logging.WARNING)
164-
monkeypatch.setenv("TOX_CONFIG_FILE", str(tmp_path))
165+
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(tmp_path))
165166
options = get_options("r")
166167
msg = (
167168
"PermissionError(13, 'Permission denied')"
168169
if sys.platform == "win32"
169170
else "IsADirectoryError(21, 'Is a directory')"
170171
)
171172
assert caplog.messages == [f"failed to read config file {tmp_path} because {msg}"]
172-
default_options["config_file"] = tmp_path
173173
assert vars(options.parsed) == default_options
174174

175175

@@ -191,7 +191,7 @@ def test_bad_option_cli_ini(
191191
""",
192192
),
193193
)
194-
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
194+
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
195195
parsed, _, __, ___, ____ = get_options("r")
196196
assert caplog.messages == [
197197
"{} key verbose as type <class 'int'> failed with {}".format(
@@ -205,7 +205,7 @@ def test_bad_option_cli_ini(
205205
def test_cli_ini_with_interpolated(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
206206
to = tmp_path / "tox.ini"
207207
to.write_text("[tox]\na = %(b)s")
208-
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
208+
monkeypatch.setenv("TOX_USER_CONFIG_FILE", str(to))
209209
conf = IniConfig()
210210
assert conf.get("a", str)
211211

0 commit comments

Comments
 (0)