Skip to content

🐛 fix(config): set_env cross-section substitution precedence - #3739

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-setenv-cross-section-override-2831
Feb 17, 2026
Merged

🐛 fix(config): set_env cross-section substitution precedence#3739
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-setenv-cross-section-override-2831

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

When a set_env section both inherits values via cross-section substitution (e.g., {[testenv]set_env}) and explicitly defines the same variable, the inherited value incorrectly overwrites the explicit one. 🔄 This means configurations like the common pattern of overriding a single variable from a base environment silently fail — the base value always wins.

[testenv]
set_env = OS_TEST_PATH=./tests/unit

[testenv:functional]
set_env =
    {[testenv]set_env}
    OS_TEST_PATH=./tests/functional  # this was silently ignored

The fix ensures that explicitly defined values in a section take precedence over values arriving from cross-section substitution expansion. This matches the intuitive "last definition wins" principle and restores the behavior users expect when layering environment configurations.

⚠️ Users who previously relied on cross-section substitution values overriding explicit values in the same section will see changed behavior. This was almost certainly unintentional in all cases, since placing a value after a substitution reference naturally implies it should override.

Fixes #2831

Explicit set_env values in a section now take precedence over
values inherited via cross-section substitution. Previously,
{[testenv]set_env} expansion would overwrite values already
defined in the current section.

Fixes tox-dev#2831
@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Feb 17, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) February 17, 2026 23:17
@gaborbernat
gaborbernat merged commit 4b78d95 into tox-dev:main Feb 17, 2026
28 checks passed
@gaborbernat
gaborbernat deleted the fix-setenv-cross-section-override-2831 branch February 18, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided bug:normal affects many people or has quite an impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in environment var inheritance in tox 4

1 participant