From 988197c7954d6e4123c1650cab090ba8f529d6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 20 Apr 2022 20:09:37 +0200 Subject: [PATCH] fix: move 'import getpass' statement to try-clause --- src/_pytest/tmpdir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index f901fd572..4cf3714bc 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -158,9 +158,9 @@ 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).""" - import getpass - try: + # In some exotic environments, getpass may not be importable. + import getpass return getpass.getuser() except (ImportError, KeyError): return None