Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0372e3b

Browse filesBrowse files
authored
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.
1 parent cc18b88 commit 0372e3b
Copy full SHA for 0372e3b

File tree

2 files changed

+13
-8
lines changed
Filter options

2 files changed

+13
-8
lines changed

‎Lib/test/support/__init__.py

Copy file name to clipboardExpand all lines: Lib/test/support/__init__.py
+1-1Lines 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
@@ -383,6 +382,7 @@ def wrapper(*args, **kw):
383382

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

‎Lib/test/support/os_helper.py

Copy file name to clipboardExpand all lines: Lib/test/support/os_helper.py
+12-7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.