Skip to content

Commit 28e8c85

Browse files
authored
Merge pull request #9871 from paulmueller/getpass-import-error
fix: move 'import getpass' statement to try-clause
2 parents 1ea7081 + 1285caa commit 28e8c85

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Ondřej Súkup
256256
Oscar Benjamin
257257
Parth Patel
258258
Patrick Hayes
259+
Paul Müller
259260
Pauli Virtanen
260261
Pavel Karateev
261262
Paweł Adamczak

changelog/9871.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bizarre (and fortunately rare) bug where the `temp_path` fixture could raise
2+
an internal error while attempting to get the current user's username.

src/_pytest/tmpdir.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ def getbasetemp(self) -> Path:
158158
def get_user() -> Optional[str]:
159159
"""Return the current user name, or None if getuser() does not work
160160
in the current environment (see #1010)."""
161-
import getpass
162-
163161
try:
162+
# In some exotic environments, getpass may not be importable.
163+
import getpass
164+
164165
return getpass.getuser()
165166
except (ImportError, KeyError):
166167
return None

0 commit comments

Comments
 (0)