testing: add regression test for get_user() swallowing OSError (#13835)#14424
Open
OfekDanny wants to merge 2 commits intopytest-dev:mainfrom
Open
testing: add regression test for get_user() swallowing OSError (#13835)#14424OfekDanny wants to merge 2 commits intopytest-dev:mainfrom
OfekDanny wants to merge 2 commits intopytest-dev:mainfrom
Conversation
…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>
Signed-off-by: Ofek Danny <ofek@kaps.co.il>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #13835.
Python 3.13 changed
getpass.getuser()to raiseOSError(instead ofImportErrororKeyError) 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 catchesOSError), but no test existed to prevent future regressions.Changes
testing/test_tmpdir.py: Addedtest_get_user_oserror()— patchesgetpass.getuserto raiseOSErrorand assertsget_user()returnsNoneinstead of propagating the exception. The test is cross-platform (noskipifneeded 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