Skip to content

Commit a5c2118

Browse files
Fix test to skip on non-Windows and use direct env var removal
Co-authored-by: RonnyPfannschmidt <[email protected]>
1 parent 9fae572 commit a5c2118

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

testing/test_tmpdir.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,19 +367,18 @@ def test_get_user(monkeypatch):
367367
assert get_user() is None
368368

369369

370+
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="win only")
370371
def test_get_user_handles_oserror(monkeypatch):
371372
"""Test that get_user() returns None when getpass.getuser() raises OSError.
372373
373374
This handles the Python 3.13+ behavior where getpass.getuser() raises
374375
OSError when no username environment variables (LOGNAME, USER, LNAME,
375376
USERNAME) are set on Windows (#11874).
376377
"""
377-
import getpass
378-
379-
def mock_getuser():
380-
raise OSError("No username set in the environment")
381-
382-
monkeypatch.setattr(getpass, "getuser", mock_getuser)
378+
monkeypatch.delenv("LOGNAME", raising=False)
379+
monkeypatch.delenv("USER", raising=False)
380+
monkeypatch.delenv("LNAME", raising=False)
381+
monkeypatch.delenv("USERNAME", raising=False)
383382
assert get_user() is None
384383

385384

0 commit comments

Comments
 (0)