Skip to content

Commit 372fa3e

Browse files
authored
bpo-40275: lazy import modules in test.support (GH-20128)
Automerge-Triggered-By: @vstinner
1 parent 4541086 commit 372fa3e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎Lib/test/support/__init__.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66
import collections.abc
77
import contextlib
88
import errno
9-
import faulthandler
109
import fnmatch
1110
import functools
12-
import gc
1311
import glob
1412
import importlib
1513
import importlib.util
1614
import os
1715
import platform
1816
import re
19-
import shutil
2017
import stat
2118
import struct
2219
import subprocess
2320
import sys
2421
import sysconfig
25-
import tempfile
2622
import _thread
2723
import threading
2824
import time
@@ -439,6 +435,7 @@ def _longpath(path):
439435
_rmdir = os.rmdir
440436

441437
def _rmtree(path):
438+
import shutil
442439
try:
443440
shutil.rmtree(path)
444441
return
@@ -891,6 +888,7 @@ def temp_dir(path=None, quiet=False):
891888
created, only a warning is issued.
892889
893890
"""
891+
import tempfile
894892
dir_created = False
895893
if path is None:
896894
path = tempfile.mkdtemp()
@@ -1436,6 +1434,7 @@ def gc_collect():
14361434
longer than expected. This function tries its best to force all garbage
14371435
objects to disappear.
14381436
"""
1437+
import gc
14391438
gc.collect()
14401439
if is_jython:
14411440
time.sleep(0.1)
@@ -1444,6 +1443,7 @@ def gc_collect():
14441443

14451444
@contextlib.contextmanager
14461445
def disable_gc():
1446+
import gc
14471447
have_gc = gc.isenabled()
14481448
gc.disable()
14491449
try:
@@ -2136,6 +2136,7 @@ def reap_children():
21362136

21372137
@contextlib.contextmanager
21382138
def start_threads(threads, unlock=None):
2139+
import faulthandler
21392140
threads = list(threads)
21402141
started = []
21412142
try:
@@ -2401,6 +2402,7 @@ def call_link(self, *args, returncode=0):
24012402

24022403
_can_xattr = None
24032404
def can_xattr():
2405+
import tempfile
24042406
global _can_xattr
24052407
if _can_xattr is not None:
24062408
return _can_xattr
@@ -2445,6 +2447,7 @@ def skip_if_pgo_task(test):
24452447

24462448
def fs_is_case_insensitive(directory):
24472449
"""Detects if the file system for the specified directory is case-insensitive."""
2450+
import tempfile
24482451
with tempfile.NamedTemporaryFile(dir=directory) as base:
24492452
base_path = base.name
24502453
case_path = base_path.upper()
@@ -2740,6 +2743,8 @@ def setswitchinterval(interval):
27402743

27412744
@contextlib.contextmanager
27422745
def disable_faulthandler():
2746+
import faulthandler
2747+
27432748
# use sys.__stderr__ instead of sys.stderr, since regrtest replaces
27442749
# sys.stderr with a StringIO which has no file descriptor when a test
27452750
# is run with -W/--verbose3.

0 commit comments

Comments
 (0)