Skip to content

✨ feat(plugin): add U flag to unset env variables#188

Merged
gaborbernat merged 2 commits into
pytest-dev:mainfrom
gaborbernat:89
Feb 11, 2026
Merged

✨ feat(plugin): add U flag to unset env variables#188
gaborbernat merged 2 commits into
pytest-dev:mainfrom
gaborbernat:89

Conversation

@gaborbernat
Copy link
Copy Markdown
Collaborator

@gaborbernat gaborbernat commented Feb 11, 2026

Currently pytest-env can only set environment variables — there's no way to remove one from os.environ. Setting a variable to an empty string (VAR=) is not the same as unsetting it: code checking if key in os.environ still sees it. This matters for libraries and frameworks that branch on variable presence rather than value.

The new U: flag follows the existing D: and R: prefix convention for INI config, and adds an unset key for the TOML inline-table format. In INI: U:DATABASE_URL. In TOML: DATABASE_URL = {unset = true}. When processed, the plugin calls os.environ.pop(key, None) instead of setting a value. ✨ Unsetting is safe to apply to variables that don't exist, and entries are processed in order so a subsequent set after an unset works as expected.

Fixes #89

@gaborbernat gaborbernat changed the title Add U flag to unset env variables ✨ feat(plugin): add U flag to unset env variables Feb 11, 2026
Setting a variable to empty string isn't the same as removing it from
the environment. The new U: flag (INI) and unset key (TOML) allow
removing variables from os.environ, following the existing D:/R: flag
pattern.

Closes pytest-dev#89
@gaborbernat gaborbernat merged commit 17f5568 into pytest-dev:main Feb 11, 2026
9 checks passed
@gaborbernat gaborbernat deleted the 89 branch February 11, 2026 15:59
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.

possible to unset an env variable

1 participant