Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions testing/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@ def test_get_user(monkeypatch):
assert get_user() is None


@pytest.mark.skipif(not sys.platform.startswith("win"), reason="win only")
def test_get_user_handles_oserror(monkeypatch):
"""Test that get_user() returns None when getpass.getuser() raises OSError.

This handles the Python 3.13+ behavior where getpass.getuser() raises
OSError when no username environment variables (LOGNAME, USER, LNAME,
USERNAME) are set on Windows (#11874).
"""
monkeypatch.delenv("LOGNAME", raising=False)
monkeypatch.delenv("USER", raising=False)
monkeypatch.delenv("LNAME", raising=False)
monkeypatch.delenv("USERNAME", raising=False)
assert get_user() is None


class TestNumberedDir:
PREFIX = "fun-"

Expand Down
Loading