[7.1.x] fix: move 'import getpass' statement to try-clause
This commit is contained in:
parent
6d75333780
commit
3a7ead6bcf
1
AUTHORS
1
AUTHORS
|
@ -256,6 +256,7 @@ Ondřej Súkup
|
||||||
Oscar Benjamin
|
Oscar Benjamin
|
||||||
Parth Patel
|
Parth Patel
|
||||||
Patrick Hayes
|
Patrick Hayes
|
||||||
|
Paul Müller
|
||||||
Pauli Virtanen
|
Pauli Virtanen
|
||||||
Pavel Karateev
|
Pavel Karateev
|
||||||
Paweł Adamczak
|
Paweł Adamczak
|
||||||
|
|
|
@ -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.
|
|
@ -158,9 +158,10 @@ class TempPathFactory:
|
||||||
def get_user() -> Optional[str]:
|
def get_user() -> Optional[str]:
|
||||||
"""Return the current user name, or None if getuser() does not work
|
"""Return the current user name, or None if getuser() does not work
|
||||||
in the current environment (see #1010)."""
|
in the current environment (see #1010)."""
|
||||||
|
try:
|
||||||
|
# In some exotic environments, getpass may not be importable.
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
try:
|
|
||||||
return getpass.getuser()
|
return getpass.getuser()
|
||||||
except (ImportError, KeyError):
|
except (ImportError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue