Skip to content

Commit 19b8d90

Browse files
authored
Revert "Remove unused imports in tests (GH-14518) (GH-14522)" (GH-14555)
This reverts commit e34b5f4.
1 parent c53173a commit 19b8d90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+73
-22
lines changed

Lib/test/libregrtest/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ def create_temp_dir(self):
587587

588588
def cleanup(self):
589589
import glob
590+
import shutil
590591

591592
path = os.path.join(self.tmp_dir, 'test_python_*')
592593
print("Cleanup %s directory" % self.tmp_dir)

Lib/test/support/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
import collections.abc
77
import contextlib
8+
import datetime
89
import errno
910
import faulthandler
1011
import fnmatch
1112
import functools
1213
import gc
1314
import importlib
1415
import importlib.util
16+
import io
1517
import logging.handlers
1618
import nntplib
1719
import os

Lib/test/test_aifc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import struct
99
import aifc
10+
import warnings
1011

1112

1213
class AifcTest(audiotests.AudioWriteTests,

Lib/test/test_argparse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Author: Steven J. Bethard <[email protected]>.
22

3+
import codecs
34
import inspect
45
import os
56
import shutil

Lib/test/test_asynchat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import errno
88
import socket
99
import sys
10+
import _thread as thread
1011
import threading
1112
import time
1213
import unittest

Lib/test/test_asyncio/test_pep492.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import types
55
import unittest
66

7+
from test import support
78
from unittest import mock
89

910
import asyncio

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from asyncio import log
1616
from asyncio import protocols
1717
from asyncio import sslproto
18+
from asyncio import tasks
1819
from test.test_asyncio import utils as test_utils
1920
from test.test_asyncio import functional as func_tests
2021

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import asyncio
2424
from asyncio import log
25+
from asyncio import base_events
2526
from asyncio import events
2627
from asyncio import unix_events
2728
from test.test_asyncio import utils as test_utils

Lib/test/test_c_locale_coercion.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import locale
44
import os
5+
import shutil
56
import subprocess
67
import sys
78
import sysconfig
89
import unittest
910
from collections import namedtuple
1011

1112
import test.support
12-
from test.support.script_helper import run_python_until_end
13-
13+
from test.support.script_helper import (
14+
run_python_until_end,
15+
interpreter_requires_environment,
16+
)
1417

1518
# Set the list of ways we expect to be able to ask for the "C" locale
1619
EXPECTED_C_LOCALE_EQUIVALENTS = ["C", "invalid.ascii"]

Lib/test/test_capi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import subprocess
1010
import sys
11+
import sysconfig
1112
import textwrap
1213
import threading
1314
import time

Lib/test/test_cmd_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import subprocess
77
import sys
8+
import sysconfig
89
import tempfile
910
import unittest
1011
from test import support

Lib/test/test_collections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import collections
44
import copy
55
import doctest
6+
import keyword
67
import operator
78
import pickle
89
from random import choice, randrange
10+
import re
911
import string
1012
import sys
1113
from test import support

Lib/test/test_contextlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit tests for contextlib.py, and other context managers."""
22

3+
import asyncio
34
import io
45
import sys
56
import tempfile

Lib/test/test_coroutines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import copy
33
import inspect
44
import pickle
5+
import re
56
import sys
67
import types
78
import unittest

Lib/test/test_docxmlrpc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import http.client
33
import sys
44
import threading
5+
from test import support
56
import unittest
67

78
def make_request_and_skipIf(condition, reason):

Lib/test/test_email/test_policy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import sys
23
import types
34
import textwrap
45
import unittest

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import errno
1010

1111
from test.support import (TESTFN, captured_stderr, check_impl_detail,
12-
check_warnings, cpython_only, gc_collect,
12+
check_warnings, cpython_only, gc_collect, run_unittest,
1313
no_tracing, unlink, import_module, script_helper,
1414
SuppressCrashReport)
1515
class NaiveException(Exception):

Lib/test/test_faulthandler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from test import support
1010
from test.support import script_helper, is_android
1111
import tempfile
12+
import threading
1213
import unittest
1314
from textwrap import dedent
1415

Lib/test/test_fork1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import unittest
1111

1212
from test.fork_wait import ForkWait
13-
from test.support import reap_children, get_attribute, verbose
13+
from test.support import (reap_children, get_attribute,
14+
import_module, verbose)
1415

1516

1617
# Skip test if fork does not exist.

Lib/test/test_frozen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import unittest
1515
from test.support import captured_stdout
16+
from importlib import util
1617

1718

1819
class TestFrozen(unittest.TestCase):

Lib/test/test_gdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# The code for testing gdb was adapted from similar work in Unladen Swallow's
44
# Lib/test/test_jit_gdb.py
55

6+
import locale
67
import os
78
import platform
89
import re

Lib/test/test_generators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pickle
44
import sys
55
import unittest
6+
import warnings
67
import weakref
78
import inspect
89

Lib/test/test_gettext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import base64
33
import gettext
4+
import locale
45
import unittest
56

67
from test import support

Lib/test/test_grammar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
from test.support import check_syntax_error
55
import inspect
66
import unittest
7+
import sys
78
# testing import *
89
from sys import *
910

1011
# different import patterns to check that __annotations__ does not interfere
1112
# with import machinery
1213
import test.ann_module as ann_module
1314
import typing
15+
from collections import ChainMap
1416
from test import ann_module2
1517
import test
1618

Lib/test/test_imaplib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from test import support
22

33
from contextlib import contextmanager
4+
import errno
45
import imaplib
56
import os.path
67
import socketserver

Lib/test/test_import/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import builtins
66
import marshal
77
import os
8+
import platform
89
import py_compile
910
import random
1011
import stat
@@ -19,9 +20,9 @@
1920

2021
import test.support
2122
from test.support import (
22-
TESTFN, forget, is_jython,
23-
make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask,
24-
unlink, unload, cpython_only, TESTFN_UNENCODABLE,
23+
EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
24+
make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask,
25+
unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE,
2526
temp_dir, DirsOnSysPath)
2627
from test.support import script_helper
2728
from test.test_importlib.util import uncache

Lib/test/test_importlib/test_locks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import sys
66
import threading
7+
import unittest
78
import weakref
89

910
from test import support

Lib/test/test_locale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import locale
44
import sys
55
import codecs
6-
6+
import warnings
77

88
class BaseLocalizedTest(unittest.TestCase):
99
#

Lib/test/test_netrc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import netrc, os, unittest, sys, tempfile, textwrap
2+
from unittest import mock
23
from test import support
34

45

Lib/test/test_os.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import decimal
1010
import errno
1111
import fractions
12+
import getpass
1213
import itertools
1314
import locale
1415
import mmap

Lib/test/test_posixpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import posixpath
33
import unittest
4+
import warnings
45
from posixpath import realpath, abspath, dirname, basename
56
from test import support, test_genericpath
67
from test.support import FakePath
@@ -11,7 +12,6 @@
1112
except ImportError:
1213
posix = None
1314

14-
1515
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
1616
# being an absolute path, so we need this.
1717

Lib/test/test_pyclbr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
Nick Mathewson
44
'''
55

6+
import os
67
import sys
78
from textwrap import dedent
89
from types import FunctionType, MethodType, BuiltinFunctionType
910
import pyclbr
1011
from unittest import TestCase, main as unittest_main
12+
from test import support
13+
from functools import partial
1114

1215
StaticMethodType = type(staticmethod(lambda: None))
1316
ClassMethodType = type(classmethod(lambda c: None))

Lib/test/test_pydoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import xml.etree
2222
import xml.etree.ElementTree
2323
import textwrap
24+
import threading
2425
from io import StringIO
2526
from collections import namedtuple
2627
from test.support.script_helper import assert_python_ok

Lib/test/test_queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Some simple queue module tests, plus some failure conditions
22
# to ensure the Queue locks remain stable.
3+
import collections
34
import itertools
45
import queue
56
import random
7+
import sys
68
import threading
79
import time
810
import unittest

Lib/test/test_resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import sys
3+
import os
34
import unittest
45
from test import support
56
import time

Lib/test/test_runpy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from test.support import (
1212
forget, make_legacy_pyc, unload, verbose, no_tracing,
1313
create_empty_file, temp_dir)
14-
from test.support.script_helper import make_script, make_zip_script
14+
from test.support.script_helper import (
15+
make_pkg, make_script, make_zip_pkg, make_zip_script)
1516

1617

1718
import runpy

Lib/test/test_sax.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
1818
from io import BytesIO, StringIO
1919
import codecs
20+
import gc
2021
import os.path
2122
import shutil
2223
from urllib.error import URLError

Lib/test/test_signal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import statistics
66
import subprocess
77
import sys
8+
import threading
89
import time
910
import unittest
1011
from test import support

Lib/test/test_smtplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import unittest
2121
from test import support, mock_socket
22-
from test.support import HOST
22+
from test.support import HOST, HOSTv4, HOSTv6
2323
from unittest.mock import Mock
2424

2525

0 commit comments

Comments
 (0)