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

Fix section substitution with setenv #3289

Merged
merged 1 commit into from
Jun 5, 2024
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/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()
Loading