Skip to content

Commit

Permalink
Fix section substitution with setenv (#3289)
Browse files Browse the repository at this point in the history
  • Loading branch information
JJLLWW committed Jun 5, 2024
1 parent 7317225 commit 489ad82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3262.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix section substitution with setenv.
1 change: 1 addition & 0 deletions src/tox/config/set_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/tox_env/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 489ad82

Please sign in to comment.