Skip to content

Commit 14d3707

Browse files
authored
Catch OSError from getpass.getuser() (#11875)
- 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
1 parent 8853a57 commit 14d3707

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ Ronny Pfannschmidt
340340
Ross Lawley
341341
Ruaridh Williamson
342342
Russel Winder
343+
Russell Martin
343344
Ryan Puddephatt
344345
Ryan Wooden
345346
Sadra Barikbin

changelog/11875.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correctly handle errors from :func:`getpass.getuser` in Python 3.13.

src/_pytest/tmpdir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def get_user() -> Optional[str]:
204204
import getpass
205205

206206
return getpass.getuser()
207-
except (ImportError, KeyError):
207+
except (ImportError, OSError, KeyError):
208208
return None
209209

210210

0 commit comments

Comments
 (0)