Skip to content

testing: add regression test for get_user() swallowing OSError (#13835)#14424

Open
OfekDanny wants to merge 2 commits intopytest-dev:mainfrom
OfekDanny:fix/13835-get-user-oserror
Open

testing: add regression test for get_user() swallowing OSError (#13835)#14424
OfekDanny wants to merge 2 commits intopytest-dev:mainfrom
OfekDanny:fix/13835-get-user-oserror

Conversation

@OfekDanny
Copy link
Copy Markdown

Summary

Closes #13835.

Python 3.13 changed getpass.getuser() to raise OSError (instead of ImportError or KeyError) when no username can be determined from the environment. This caused pytest to crash on Python 3.13+/Windows when username env vars were absent.

The exception-handling fix was already applied in #11875 (get_user() now catches OSError), but no test existed to prevent future regressions.

Changes

  • testing/test_tmpdir.py: Added test_get_user_oserror() — patches getpass.getuser to raise OSError and asserts get_user() returns None instead of propagating the exception. The test is cross-platform (no skipif needed since it mocks the function directly).
  • changelog/13835.bugfix.rst: Changelog entry for the already-fixed bug, so the fix is documented in the next release notes.

Test output

testing/test_tmpdir.py::test_get_user_uid_not_found PASSED
testing/test_tmpdir.py::test_get_user SKIPPED (win only)
testing/test_tmpdir.py::test_get_user_oserror PASSED

…t-dev#13835)

Python 3.13 changed getpass.getuser() to raise OSError (instead of
ImportError or KeyError) when no username can be determined from the
environment. The fix was already applied in pytest-dev#11875, but no test existed
to prevent regressions.

Add test_get_user_oserror() which patches getpass.getuser to raise
OSError and asserts that get_user() returns None rather than propagating
the exception. Also adds the corresponding changelog entry.

Closes pytest-dev#13835

Signed-off-by: Ofek Danny <ofek@kaps.co.il>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 27, 2026
Signed-off-by: Ofek Danny <ofek@kaps.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pytest tmpdir crashes on Python 3.13+/Windows when no username env vars are set (getpass.getuser now raises OSError)

2 participants