Skip to content

🐛 fix(config): set_env file| no longer overrides later values - #3740

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-setenv-file-order-3335
Feb 17, 2026
Merged

🐛 fix(config): set_env file| no longer overrides later values#3740
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix-setenv-file-order-3335

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

When set_env mixes file| references with inline variable definitions, values from the env file always took precedence regardless of ordering. This broke the intuitive "last definition wins" rule that works correctly for purely inline definitions.

[testenv]
set_env =
    file|.env       # .env contains FOO=BAR
    FOO=QUX         # expected QUX, got BAR

🔧 The fix tracks which keys are defined after each file| reference during parsing, then skips those keys when loading the env file. Variables only defined in the file still come through normally, while explicit inline overrides now take precedence as expected.

⚠️ Users who relied on env file values silently overriding later inline definitions will see changed behavior. The new behavior matches the principle of least surprise — definitions appearing later in the config win.

Fixes #3335

Values defined after a file| reference now take precedence
over values loaded from the env file, matching the "last
definition wins" behavior of inline set_env values.

Fixes tox-dev#3335
@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:44
@gaborbernat
gaborbernat merged commit b6adbdc into tox-dev:main Feb 17, 2026
28 checks passed
@gaborbernat
gaborbernat deleted the fix-setenv-file-order-3335 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.

variable assingment order inconsistency when using file| in set_env

1 participant