Skip to content

Commit 078733c

Browse files
authored
Merge pull request #9872 from pytest-dev/backport-9871-to-7.1.x
2 parents 6d75333 + 3a7ead6 commit 078733c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

AUTHORS

+1
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

+2
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

+3-2
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)