From 988197c7954d6e4123c1650cab090ba8f529d6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 20 Apr 2022 20:09:37 +0200 Subject: [PATCH 1/7] fix: move 'import getpass' statement to try-clause --- src/_pytest/tmpdir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index f901fd5727c..4cf3714bcd1 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -158,9 +158,9 @@ def getbasetemp(self) -> Path: def get_user() -> Optional[str]: """Return the current user name, or None if getuser() does not work in the current environment (see #1010).""" - import getpass - try: + # In some exotic environments, getpass may not be importable. + import getpass return getpass.getuser() except (ImportError, KeyError): return None From 8514fab409fbcf43ec9e8cd7a39a27635a4b6e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 20 Apr 2022 20:15:29 +0200 Subject: [PATCH 2/7] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 69e71fa10d4..5ab1c2f7a03 100644 --- a/AUTHORS +++ b/AUTHORS @@ -256,6 +256,7 @@ Ondřej Súkup Oscar Benjamin Parth Patel Patrick Hayes +Paul Müller Pauli Virtanen Pavel Karateev Paweł Adamczak From ac9b65d890044656a592c41391c0734f4e67f9df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:15:48 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/tmpdir.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 4cf3714bcd1..12dc463a2a2 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -161,6 +161,7 @@ def get_user() -> Optional[str]: try: # In some exotic environments, getpass may not be importable. import getpass + return getpass.getuser() except (ImportError, KeyError): return None From 2b9f8f2f9b98b492f438ec5d4b0284706aae8498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 20 Apr 2022 20:20:53 +0200 Subject: [PATCH 4/7] Create 9871.bugfix.rst --- changelog/9871.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/9871.bugfix.rst diff --git a/changelog/9871.bugfix.rst b/changelog/9871.bugfix.rst new file mode 100644 index 00000000000..0986414f2bf --- /dev/null +++ b/changelog/9871.bugfix.rst @@ -0,0 +1 @@ +Handle ``ImportError`` for ``getpass`` import in ``_pytest.tempdir.get_user`` From 715d0ca9d0aa6a6136487336193c98e2604a0353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 20 Apr 2022 20:21:44 +0200 Subject: [PATCH 5/7] cleanup --- src/_pytest/tmpdir.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 12dc463a2a2..4cf3714bcd1 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -161,7 +161,6 @@ def get_user() -> Optional[str]: try: # In some exotic environments, getpass may not be importable. import getpass - return getpass.getuser() except (ImportError, KeyError): return None From 12971a37e121c5761bbecab32dbca24231a59065 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:23:03 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/tmpdir.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 4cf3714bcd1..12dc463a2a2 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -161,6 +161,7 @@ def get_user() -> Optional[str]: try: # In some exotic environments, getpass may not be importable. import getpass + return getpass.getuser() except (ImportError, KeyError): return None From 1285caadf29ab7801ff24ace711de7b66fc20a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 21 Apr 2022 00:18:47 +0200 Subject: [PATCH 7/7] Update 9871.bugfix.rst --- changelog/9871.bugfix.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog/9871.bugfix.rst b/changelog/9871.bugfix.rst index 0986414f2bf..ed787b3da34 100644 --- a/changelog/9871.bugfix.rst +++ b/changelog/9871.bugfix.rst @@ -1 +1,2 @@ -Handle ``ImportError`` for ``getpass`` import in ``_pytest.tempdir.get_user`` +Fix a bizarre (and fortunately rare) bug where the `temp_path` fixture could raise +an internal error while attempting to get the current user's username.