Skip to content

Commit e983ca8

Browse files
authored
[3.12] gh-111881: Use lazy import in test.support (#111885) (#111890)
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. (cherry picked from commit 0372e3b)
1 parent e0d827d commit e983ca8

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import contextlib
77
import dataclasses
88
import functools
9-
import getpass
109
import opcode
1110
import os
1211
import re
@@ -382,6 +381,7 @@ def wrapper(*args, **kw):
382381

383382
def skip_if_buildbot(reason=None):
384383
"""Decorator raising SkipTest if running on a buildbot."""
384+
import getpass
385385
if not reason:
386386
reason = 'not suitable for buildbots'
387387
try:

Lib/test/support/os_helper.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import unittest
1111
import warnings
1212

13+
from test import support
14+
1315

1416
# Filename used for testing
1517
TESTFN_ASCII = '@test'
@@ -720,13 +722,16 @@ def __exit__(self, *ignore_exc):
720722

721723

722724
try:
723-
import ctypes
724-
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
725-
726-
ERROR_FILE_NOT_FOUND = 2
727-
DDD_REMOVE_DEFINITION = 2
728-
DDD_EXACT_MATCH_ON_REMOVE = 4
729-
DDD_NO_BROADCAST_SYSTEM = 8
725+
if support.MS_WINDOWS:
726+
import ctypes
727+
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
728+
729+
ERROR_FILE_NOT_FOUND = 2
730+
DDD_REMOVE_DEFINITION = 2
731+
DDD_EXACT_MATCH_ON_REMOVE = 4
732+
DDD_NO_BROADCAST_SYSTEM = 8
733+
else:
734+
raise AttributeError
730735
except (ImportError, AttributeError):
731736
def subst_drive(path):
732737
raise unittest.SkipTest('ctypes or kernel32 is not available')

0 commit comments

Comments
 (0)