Skip to content

🐛 fix(dotenv): preserve binding order with skip-if-set - #358

Merged
gaborbernat merged 3 commits into
pytest-dev:mainfrom
narayana006:fix/dotenv-binding-order
Nov 23, 2026
Merged

gaborbernat merged 3 commits into
pytest-dev:mainfrom
narayana006:fix/dotenv-binding-order

Conversation

@narayana006

@narayana006 narayana006 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

With env_files_skip_if_set enabled, a reference between two definitions expanded using the last definition in the file. A reference now uses the value available at that line. For example, given BASE=first, DERIVED=${BASE}, then BASE=last, pytest sees DERIVED=first and BASE=last. #340 describes the original skip behavior and this edge case.

The dotenv loader resolves references before assigning each variable’s final value. It uses shell values for variables the skip rule preserves and matches names case-insensitively on Windows.

pre-commit-ci Bot and others added 2 commits November 20, 2026 04:03
A dotenv reference can use a preceding binding or a kept shell value.
On Windows, different spellings of the same name must resolve and
assign as one variable. Reuse one lookup table per file to avoid
copying it for every value.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 23, 2026
@gaborbernat gaborbernat changed the title Preserve dotenv binding order with skip-if-set 🐛 fix(dotenv): preserve binding order with skip-if-set Nov 23, 2026
@gaborbernat
gaborbernat merged commit 7f0f608 into pytest-dev:main Nov 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants