From e5584da625607f056f01b14abe5d444d8a754a80 Mon Sep 17 00:00:00 2001 From: Russell Martin Date: Sun, 28 Jan 2024 17:31:37 -0500 Subject: [PATCH] Catch `OSError` from `getpass.getuser()` - 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`. --- AUTHORS | 1 + src/_pytest/tmpdir.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 803bb2b18..bea582046 100644 --- a/AUTHORS +++ b/AUTHORS @@ -340,6 +340,7 @@ Ronny Pfannschmidt Ross Lawley Ruaridh Williamson Russel Winder +Russell Martin Ryan Puddephatt Ryan Wooden Sadra Barikbin diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 937b1687a..75391adbc 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -204,7 +204,7 @@ def get_user() -> Optional[str]: import getpass return getpass.getuser() - except (ImportError, KeyError): + except (ImportError, OSError, KeyError): return None