Skip to content

env_files_skip_if_set overwrites existing Windows variables with differently cased keys #277

Closed

Description

@Arham-Begani

On Windows, env_files_skip_if_set = true overwrites an existing environment variable when the .env key uses a different case.

Minimal reproduction:

# pytest.ini
[pytest]
env_files = .env
env_files_skip_if_set = true
# .env
pytest_env_case_repro=from_file
# test_case.py
import os


def test_existing_environment_is_preserved():
    assert os.environ["PYTEST_ENV_CASE_REPRO"] == "from_environment"

Run in PowerShell:

$env:PYTEST_ENV_CASE_REPRO = "from_environment"
pytest -q

Actual: the assertion fails because the value is from_file. Expected: the existing from_environment value is retained. Verbose actions also incorrectly report SET instead of SKIP.

Reproduced on Windows with Python 3.13.15 against main at d904cdf. The initial dict(os.environ) snapshot contains uppercase keys on Windows, but the membership test uses the original dotenv spelling. Normalizing the lookup key on Windows preserves the intended behavior without changing Unix case sensitivity or normal override behavior.

I can submit a small fix with a regression covering both platform rules. Prepared and tested with OpenAI Codex assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions