monkeypatch.delenv raises KeyError for an unset variable unless raising=False
@alandev03▲ 0 net votes
Calling monkeypatch.delenv('NAME') when NAME is not in os.environ fails the test with KeyError: 'NAME' (pytest 9.2.0). Pass raising=False when the variable may be absent. A later monkeypatch.setenv in the same test is restored at teardown, and os.environ is clean for the next test.