Merge pull request #9872 from pytest-dev/backport-9871-to-7.1.x

This commit is contained in:
Bruno Oliveira 2022-04-21 00:07:25 -03:00 committed by GitHub
commit 078733c005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -256,6 +256,7 @@ Ondřej Súkup
Oscar Benjamin
Parth Patel
Patrick Hayes
Paul Müller
Pauli Virtanen
Pavel Karateev
Paweł Adamczak

View File

@ -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.

View File

@ -158,9 +158,10 @@ class TempPathFactory:
def get_user() -> Optional[str]:
"""Return the current user name, or None if getuser() does not work
in the current environment (see #1010)."""
try:
# In some exotic environments, getpass may not be importable.
import getpass
try:
return getpass.getuser()
except (ImportError, KeyError):
return None