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.
This commit is contained in:
Victor Stinner 2023-11-09 15:38:13 +01:00 committed by GitHub
parent cc18b886a5
commit 0372e3b02a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -6,7 +6,6 @@ if __name__ != 'test.support':
import contextlib import contextlib
import dataclasses import dataclasses
import functools import functools
import getpass
import _opcode import _opcode
import os import os
import re import re
@ -383,6 +382,7 @@ def requires_mac_ver(*min_version):
def skip_if_buildbot(reason=None): def skip_if_buildbot(reason=None):
"""Decorator raising SkipTest if running on a buildbot.""" """Decorator raising SkipTest if running on a buildbot."""
import getpass
if not reason: if not reason:
reason = 'not suitable for buildbots' reason = 'not suitable for buildbots'
try: try:

View file

@ -10,6 +10,8 @@ import time
import unittest import unittest
import warnings import warnings
from test import support
# Filename used for testing # Filename used for testing
TESTFN_ASCII = '@test' TESTFN_ASCII = '@test'
@ -720,6 +722,7 @@ class EnvironmentVarGuard(collections.abc.MutableMapping):
try: try:
if support.MS_WINDOWS:
import ctypes import ctypes
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
@ -727,6 +730,8 @@ try:
DDD_REMOVE_DEFINITION = 2 DDD_REMOVE_DEFINITION = 2
DDD_EXACT_MATCH_ON_REMOVE = 4 DDD_EXACT_MATCH_ON_REMOVE = 4
DDD_NO_BROADCAST_SYSTEM = 8 DDD_NO_BROADCAST_SYSTEM = 8
else:
raise AttributeError
except (ImportError, AttributeError): except (ImportError, AttributeError):
def subst_drive(path): def subst_drive(path):
raise unittest.SkipTest('ctypes or kernel32 is not available') raise unittest.SkipTest('ctypes or kernel32 is not available')