Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2350.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not interpolate values when parsing ``tox.ini`` configuration files - by :user:`gaborbernat`.
2 changes: 1 addition & 1 deletion src/tox/config/cli/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self) -> None:
self.config_file = self.config_file.absolute()
try:

parser = ConfigParser()
parser = ConfigParser(interpolation=None)
with self.config_file.open() as file_handler:
parser.read_file(file_handler)
self.has_tox_section = parser.has_section(CORE.key)
Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/source/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IniSource(Source, ABC):

def __init__(self, path: Path, content: str | None = None) -> None:
super().__init__(path)
self._parser = ConfigParser()
self._parser = ConfigParser(interpolation=None)
if content is None:
if not path.exists():
raise ValueError
Expand Down
9 changes: 9 additions & 0 deletions tests/config/cli/test_cli_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
from pytest_mock import MockerFixture

from tox.config.cli.ini import IniConfig
from tox.config.cli.parse import get_options
from tox.config.loader.api import Override
from tox.pytest import CaptureFixture, LogCaptureFixture, MonkeyPatch
Expand Down Expand Up @@ -190,3 +191,11 @@ def test_bad_option_cli_ini(
),
]
assert vars(parsed) == default_options


def test_cli_ini_with_interpolated(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
to = tmp_path / "tox.ini"
to.write_text("[tox]\na = %(b)s")
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
conf = IniConfig()
assert conf.get("a", str)
2 changes: 1 addition & 1 deletion tests/config/loader/ini/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def mk_ini_conf(tmp_path: Path) -> Callable[[str], ConfigParser]:
def _func(raw: str) -> ConfigParser:
filename = tmp_path / "demo.ini"
filename.write_bytes(raw.encode("utf-8")) # win32: avoid CR normalization - what you pass is what you get
parser = ConfigParser()
parser = ConfigParser(interpolation=None)
with filename.open() as file_handler:
parser.read_file(file_handler)
return parser
Expand Down
10 changes: 10 additions & 0 deletions tests/config/source/test_source_ini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path

from tox.config.loader.section import Section
from tox.config.source.ini import IniSource


def test_source_ini_with_interpolated(tmp_path: Path) -> None:
loader = IniSource(tmp_path, content="[tox]\na = %(c)s").get_loader(Section(None, "tox"), {})
assert loader is not None
loader.load_raw("a", None, None)
8 changes: 4 additions & 4 deletions tests/session/cmd/test_show_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_show_config_default_run_env(tox_project: ToxProjectCreator, monkeypatch
outcome = list(state.envs.iter(only_active=False))
assert outcome == [name]
monkeypatch.delenv("TERM", raising=False) # disable conditionally set flag
parser = ConfigParser()
parser = ConfigParser(interpolation=None)
parser.read_string(result.out)
assert list(parser.sections()) == [f"testenv:{name}", "tox"]

Expand Down Expand Up @@ -122,7 +122,7 @@ def test_show_config_pkg_env_once(
)
result = project.run("c")
result.assert_success()
parser = ConfigParser()
parser = ConfigParser(interpolation=None)
parser.read_string(result.out)
sections = set(parser.sections())
assert sections == {"testenv:.pkg", f"testenv:.pkg-{impl}{prev_ver}", f"testenv:py{prev_ver}", "testenv:py", "tox"}
Expand All @@ -138,7 +138,7 @@ def test_show_config_pkg_env_skip(
)
result = project.run("c")
result.assert_success()
parser = ConfigParser()
parser = ConfigParser(interpolation=None)
parser.read_string(result.out)
sections = set(parser.sections())
assert sections == {"testenv:.pkg", "tox", "testenv:py", f"testenv:py{prev_ver}"}
Expand All @@ -148,7 +148,7 @@ def test_show_config_select_only(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[tox]\nenv_list=\n a\n b", "pyproject.toml": ""})
result = project.run("c", "-e", ".pkg,b,.pkg")
result.assert_success()
parser = ConfigParser()
parser = ConfigParser(interpolation=None)
parser.read_string(result.out)
sections = list(parser.sections())
assert sections == ["testenv:.pkg", "testenv:b"]
Expand Down