Skip to content

🐛 fix(config): set_env cross-section substitution loses values - #3737

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

🐛 fix(config): set_env cross-section substitution loses values#3737
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-setenv-substitution-override

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Feb 17, 2026

Copy link
Copy Markdown
Member

When a child environment inherits set_env via cross-section substitution (e.g., set_env = {[testenv]set_env}), environment variables like PYTHONHASHSEED were silently replaced with their auto-generated defaults. This meant explicitly setting PYTHONHASHSEED=0 in 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.

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.
@gaborbernat
gaborbernat enabled auto-merge (squash) February 17, 2026 22:42
@gaborbernat
gaborbernat merged commit a3b2b01 into tox-dev:main Feb 17, 2026
28 checks passed
@gaborbernat
gaborbernat deleted the fix-setenv-substitution-override branch February 17, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set_env substitution doesn't pass PYTHONHASHSEED in tox 4.x

1 participant