summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-09 14:38:13 (GMT)
committerGitHub <noreply@github.com>2023-11-09 14:38:13 (GMT)
commit0372e3b02a7e3dc1c564dba94dcd817c5472b04f (patch)
tree1f6c2660ccc0252ebff00c00ebc9fe9e5647153a /Lib/test/support
parentcc18b886a51672c59622837a2b8e83bf6be28c58 (diff)
downloadcpython-0372e3b02a7e3dc1c564dba94dcd817c5472b04f.zip
cpython-0372e3b02a7e3dc1c564dba94dcd817c5472b04f.tar.gz
cpython-0372e3b02a7e3dc1c564dba94dcd817c5472b04f.tar.bz2
gh-111881: Use lazy import in test.support (#111885)
* Import lazily getpass in test.support * Only import ctypes on Windows in test.support.os_helper.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/support/os_helper.py19
2 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index f64f88d..1057aac 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -6,7 +6,6 @@ if __name__ != 'test.support':
import contextlib
import dataclasses
import functools
-import getpass
import _opcode
import os
import re
@@ -383,6 +382,7 @@ def requires_mac_ver(*min_version):
def skip_if_buildbot(reason=None):
"""Decorator raising SkipTest if running on a buildbot."""
+ import getpass
if not reason:
reason = 'not suitable for buildbots'
try:
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index 821a4b1..46ae53a 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -10,6 +10,8 @@ import time
import unittest
import warnings
+from test import support
+
# Filename used for testing
TESTFN_ASCII = '@test'
@@ -720,13 +722,16 @@ class EnvironmentVarGuard(collections.abc.MutableMapping):
try:
- import ctypes
- kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
-
- ERROR_FILE_NOT_FOUND = 2
- DDD_REMOVE_DEFINITION = 2
- DDD_EXACT_MATCH_ON_REMOVE = 4
- DDD_NO_BROADCAST_SYSTEM = 8
+ if support.MS_WINDOWS:
+ import ctypes
+ kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
+
+ ERROR_FILE_NOT_FOUND = 2
+ DDD_REMOVE_DEFINITION = 2
+ DDD_EXACT_MATCH_ON_REMOVE = 4
+ DDD_NO_BROADCAST_SYSTEM = 8
+ else:
+ raise AttributeError
except (ImportError, AttributeError):
def subst_drive(path):
raise unittest.SkipTest('ctypes or kernel32 is not available')