Skip to content

fix: respect Windows key casing when preserving existing env values - #278

Merged
gaborbernat merged 2 commits into
pytest-dev:mainfrom
Arham-Begani:fix/windows-env-file-skip-if-set
Oct 18, 2026
Merged

gaborbernat merged 2 commits into
pytest-dev:mainfrom
Arham-Begani:fix/windows-env-file-skip-if-set

Conversation

@Arham-Begani

Copy link
Copy Markdown
Contributor

Fixes #277.

env_files_skip_if_set = true can overwrite an existing variable on Windows when the dotenv key uses different casing. Windows' os.environ normalizes keys to uppercase, but the dict(os.environ) snapshot is queried using the unnormalized file spelling. The verbose report consequently says SET rather than SKIP.

Normalize the snapshot lookup key on Windows, preserving the original key for assignment and reporting. Unix lookup remains case-sensitive. Four regression cases cover both platform rules and identical/different key spellings, including the reported action and preserved value.

Validation:

  • Before the fix: the new regression had 1 failure and 3 passes; a real Windows CLI reproduction also failed with from_file instead of from_environment.
  • After the fix: all 4 regression cases and the real Windows CLI reproduction pass.
  • Ruff lint and formatting checks pass (0.17.1), as does git diff --check.
  • The unchanged project check workflow on this exact commit passed all 9 jobs: Python 3.11–3.15, free-threaded 3.15, types, development setup and package checks. The Python 3.13 job reports 107 tests passed and 100% coverage.
  • The full local Windows run reported 42 passed and 65 failed; the existing pytester tests require symlink creation, which fails here with WinError 1314. No tests were skipped or altered to hide that limitation. The full suite passed in the Linux workflow above.

AI assistance: OpenAI Codex assisted with investigation, implementation, tests and this description. The Windows reproduction and hosted workflow were actually executed; no external model service or credentials were needed.

@gaborbernat
gaborbernat merged commit af9a6d3 into pytest-dev:main Oct 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env_files_skip_if_set overwrites existing Windows variables with differently cased keys

2 participants