From 489ad821e5b9c6d5aff500e1b3abc4292f52a2dc Mon Sep 17 00:00:00 2001 From: JJLLWW <70631023+JJLLWW@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:15:10 +0100 Subject: [PATCH] Fix section substitution with setenv (#3289) --- docs/changelog/3262.bugfix.rst | 1 + src/tox/config/set_env.py | 1 + tests/tox_env/test_api.py | 11 +++++++++++ 3 files changed, 13 insertions(+) create mode 100644 docs/changelog/3262.bugfix.rst diff --git a/docs/changelog/3262.bugfix.rst b/docs/changelog/3262.bugfix.rst new file mode 100644 index 000000000..1cd5c12b8 --- /dev/null +++ b/docs/changelog/3262.bugfix.rst @@ -0,0 +1 @@ +Fix section substitution with setenv. diff --git a/src/tox/config/set_env.py b/src/tox/config/set_env.py index 3d98c902d..47fb62238 100644 --- a/src/tox/config/set_env.py +++ b/src/tox/config/set_env.py @@ -93,6 +93,7 @@ def __iter__(self) -> Iterator[str]: expanded_line = self._replacer(line, ConfigLoadArgs([], self._name, self._env_name)) sub_raw = dict(self._extract_key_value(sub_line) for sub_line in expanded_line.splitlines() if sub_line) self._raw.update(sub_raw) + self.changed = True # loading while iterating can cause these values to be missed yield from sub_raw.keys() def update(self, param: Mapping[str, str] | SetEnv, *, override: bool = True) -> None: diff --git a/tests/tox_env/test_api.py b/tests/tox_env/test_api.py index dd741ac74..8ac3bfffa 100644 --- a/tests/tox_env/test_api.py +++ b/tests/tox_env/test_api.py @@ -21,3 +21,14 @@ def test_dont_cleanup_temp_dir(tox_project: ToxProjectCreator, tmp_path: Path) - result = project.run() result.assert_success() assert (tmp_path / "foo" / "bar").exists() + + +def test_setenv_section_substitution(tox_project: ToxProjectCreator) -> None: + ini = """[variables] + var = VAR = val + [testenv] + setenv = {[variables]var} + commands = python -c 'import os; os.environ["VAR"]'""" + project = tox_project({"tox.ini": ini}) + result = project.run() + result.assert_success()