Skip to content

Commit

Permalink
Catch OSError from getpass.getuser() (#11875)
Browse files Browse the repository at this point in the history
- Previously, `getpass.getuser()` would leak an ImportError if the
  USERNAME environment variable was not set on Windows because the `pwd`
  module cannot be imported.
- Starting in Python 3.13.0a3, it only raises `OSError`.

Fixes #11874
  • Loading branch information
rmartin16 committed Jan 29, 2024
1 parent 8853a57 commit 14d3707
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ Ronny Pfannschmidt
Ross Lawley
Ruaridh Williamson
Russel Winder
Russell Martin
Ryan Puddephatt
Ryan Wooden
Sadra Barikbin
Expand Down
1 change: 1 addition & 0 deletions changelog/11875.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly handle errors from :func:`getpass.getuser` in Python 3.13.
2 changes: 1 addition & 1 deletion src/_pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def get_user() -> Optional[str]:
import getpass

return getpass.getuser()
except (ImportError, KeyError):
except (ImportError, OSError, KeyError):
return None


Expand Down

0 comments on commit 14d3707

Please sign in to comment.