Skip to content

🐛 fix(unset): let skip-if-set keep the variable - #337

Merged
gaborbernat merged 1 commit into
pytest-dev:mainfrom
gaborbernat:fix/unset-skip-if-set
Nov 17, 2026
Merged

gaborbernat merged 1 commit into
pytest-dev:mainfrom
gaborbernat:fix/unset-skip-if-set

Conversation

@gaborbernat

Copy link
Copy Markdown
Collaborator

_apply_entries tested entry.unset before entry.skip_if_set (old lines), so an entry marked both ways removed a variable that was already set. With KEEP exported, the INI entry D:U:KEEP or the TOML entry KEEP = { unset = true, skip_if_set = true } started the session without KEEP, while the README says skip_if_set leaves an existing variable unchanged and that flags combine in any order. 🐛 After this PR the existing variable is kept. Fixes #329.

Unset ran before the skip check

The skip check sat in an elif behind the unset branch, so it was reached only by entries that were not unset, and neither parser rejects the combination. _apply_entries now checks skip-if-set first, then unset, then the assignment.

Behavior changes

An entry that combines D: with U:, or skip_if_set with unset, leaves an existing variable in place, and --pytest-env-verbose reports it as SKIP. When the variable is not set, the entry has nothing to remove and the result is the same as before. A configuration that used the combination to strip a variable has to drop D: or skip_if_set. Entries with only one of the two flags behave as before.

Reported by Anthropic's OSS Scanner: ANT-2026-1TT2R7UY.

An entry marked both unset and skip-if-set removed a variable that was
already set, because the unset branch ran first. The README says
skip_if_set leaves an existing variable unchanged and that flags combine
in any order.

Reported by Anthropic's OSS Scanner: ANT-2026-1TT2R7UY.

Fixes pytest-dev#329
@gaborbernat gaborbernat added the bug Something isn't working label Nov 17, 2026
@gaborbernat
gaborbernat merged commit 22ac638 into pytest-dev:main Nov 17, 2026
20 checks passed
@gaborbernat
gaborbernat deleted the fix/unset-skip-if-set branch November 17, 2026 23:31
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.

An entry with both unset and skip-if-set removes an existing variable

1 participant