Skip to content
Closed
Changes from 2 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
16 changes: 16 additions & 0 deletions testing/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,22 @@ def test_get_user(monkeypatch):
assert get_user() is None


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).
"""
import getpass

def mock_getuser():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this tests the wrong thing

The test shoul skip on non affected platforms and use direct values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in commit 9c8e8d8. The test now:

  • Skips on non-Windows platforms using @pytest.mark.skipif(not sys.platform.startswith("win"), reason="win only")
  • Uses direct environment variable removal with monkeypatch.delenv() for all four variables (LOGNAME, USER, LNAME, USERNAME) instead of mocking

raise OSError("No username set in the environment")

monkeypatch.setattr(getpass, "getuser", mock_getuser)
assert get_user() is None


class TestNumberedDir:
PREFIX = "fun-"

Expand Down
Loading