🐛 fix(config): set_env cross-section substitution loses values - #3737
Merged
gaborbernat merged 1 commit intoFeb 17, 2026
Merged
Conversation
When using cross-section substitution like {[testenv]set_env} in a
child environment, expanded values now correctly override default
environment variables like PYTHONHASHSEED. Previously the defaults
were materialized before the substitution was expanded.
Fixes tox-dev#2872.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a child environment inherits
set_envvia cross-section substitution (e.g.,set_env = {[testenv]set_env}), environment variables likePYTHONHASHSEEDwere silently replaced with their auto-generated defaults. This meant explicitly settingPYTHONHASHSEED=0in the base environment had no effect in child environments that referenced it — the child would always get a random hash seed. 🐛The root cause is a timing issue: tox applies default environment variables (including
PYTHONHASHSEED) during post-processing, before the{[testenv]...}substitution is expanded. Since the unexpanded reference is not yet in the raw config dict, the defaults are materialized first. When the substitution later expands and populates the raw dict, the already-materialized default takes precedence during lookup.The fix ensures that when a deferred substitution is expanded, any previously materialized defaults for the same keys are evicted, allowing the explicitly configured values to take priority as intended.
Fixes #2872.