Skip to content

Commit 988197c

Browse files
authored
fix: move 'import getpass' statement to try-clause
1 parent 1ea7081 commit 988197c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/_pytest/tmpdir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ 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
164164
return getpass.getuser()
165165
except (ImportError, KeyError):
166166
return None

0 commit comments

Comments
 (0)