Skip to content

Commit

Permalink
Merge pull request #9872 from pytest-dev/backport-9871-to-7.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored Apr 21, 2022
2 parents 6d75333 + 3a7ead6 commit 078733c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ Ondřej Súkup
Oscar Benjamin
Parth Patel
Patrick Hayes
Paul Müller
Pauli Virtanen
Pavel Karateev
Paweł Adamczak
Expand Down
2 changes: 2 additions & 0 deletions changelog/9871.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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.
5 changes: 3 additions & 2 deletions src/_pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ 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
Expand Down

0 comments on commit 078733c

Please sign in to comment.