[Python-checkins] bpo-40275: Use new test.support helper submodules in tests (GH-21317)

Hai Shi webhook-mailer at python.org
Mon Jul 6 08:30:05 EDT 2020


https://github.com/python/cpython/commit/deb016224cc506503fb05e821a60158c83918ed4
commit: deb016224cc506503fb05e821a60158c83918ed4
branch: master
author: Hai Shi <shihai1992 at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-07-06T14:29:49+02:00
summary:

bpo-40275: Use new test.support helper submodules in tests (GH-21317)

files:
M Lib/distutils/tests/support.py
M Lib/distutils/tests/test_build_ext.py
M Lib/distutils/tests/test_filelist.py
M Lib/distutils/tests/test_spawn.py
M Lib/test/test_dbm_gnu.py
M Lib/test/test_eof.py
M Lib/test/test_hashlib.py
M Lib/test/test_idle.py
M Lib/test/test_imaplib.py
M Lib/test/test_marshal.py
M Lib/test/test_py_compile.py
M Lib/test/test_set.py
M Lib/test/test_socket.py
M Lib/test/test_sysconfig.py
M Lib/test/test_traceback.py
M Lib/test/test_unicode.py
M Lib/test/test_xml_etree.py
M Lib/test/test_zipfile.py

diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py
index 259af882ec0e9..23b907b607efa 100644
--- a/Lib/distutils/tests/support.py
+++ b/Lib/distutils/tests/support.py
@@ -6,7 +6,7 @@
 import unittest
 import sysconfig
 from copy import deepcopy
-import test.support
+from test.support import os_helper
 
 from distutils import log
 from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
@@ -64,7 +64,7 @@ def tearDown(self):
         super().tearDown()
         while self.tempdirs:
             tmpdir = self.tempdirs.pop()
-            test.support.rmtree(tmpdir)
+            os_helper.rmtree(tmpdir)
 
     def mkdtemp(self):
         """Create a temporary directory that will be cleaned up.
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index 5e47e0773a964..f9e0d766d870e 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -15,6 +15,7 @@
 
 import unittest
 from test import support
+from test.support import os_helper
 from test.support.script_helper import assert_python_ok
 
 # http://bugs.python.org/issue4373
@@ -38,7 +39,7 @@ def setUp(self):
         # bpo-30132: On Windows, a .pdb file may be created in the current
         # working directory. Create a temporary working directory to cleanup
         # everything at the end of the test.
-        change_cwd = support.change_cwd(self.tmp_dir)
+        change_cwd = os_helper.change_cwd(self.tmp_dir)
         change_cwd.__enter__()
         self.addCleanup(change_cwd.__exit__, None, None, None)
 
diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py
index 2c26c22617ed4..cee97d439e6df 100644
--- a/Lib/distutils/tests/test_filelist.py
+++ b/Lib/distutils/tests/test_filelist.py
@@ -8,7 +8,6 @@
 from distutils.filelist import glob_to_re, translate_pattern, FileList
 from distutils import filelist
 
-import test.support
 from test.support import os_helper
 from test.support import captured_stdout, run_unittest
 from distutils.tests import support
@@ -298,7 +297,7 @@ def test_process_template(self):
 class FindAllTestCase(unittest.TestCase):
     @os_helper.skip_unless_symlink
     def test_missing_symlink(self):
-        with test.support.temp_cwd():
+        with os_helper.temp_cwd():
             os.symlink('foo', 'bar')
             self.assertEqual(filelist.findall(), [])
 
@@ -308,13 +307,13 @@ def test_basic_discovery(self):
         '.' as the parameter, the dot should be omitted from
         the results.
         """
-        with test.support.temp_cwd():
+        with os_helper.temp_cwd():
             os.mkdir('foo')
             file1 = os.path.join('foo', 'file1.txt')
-            test.support.create_empty_file(file1)
+            os_helper.create_empty_file(file1)
             os.mkdir('bar')
             file2 = os.path.join('bar', 'file2.txt')
-            test.support.create_empty_file(file2)
+            os_helper.create_empty_file(file2)
             expected = [file2, file1]
             self.assertEqual(sorted(filelist.findall()), expected)
 
@@ -323,9 +322,9 @@ def test_non_local_discovery(self):
         When findall is called with another path, the full
         path name should be returned.
         """
-        with test.support.temp_dir() as temp_dir:
+        with os_helper.temp_dir() as temp_dir:
             file1 = os.path.join(temp_dir, 'file1.txt')
-            test.support.create_empty_file(file1)
+            os_helper.create_empty_file(file1)
             expected = [file1]
             self.assertEqual(filelist.findall(temp_dir), expected)
 
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index cf1faad5f4dd5..3647bab7b1cbc 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -4,7 +4,7 @@
 import sys
 import unittest.mock
 from test.support import run_unittest, unix_shell
-from test import support as test_support
+from test.support import os_helper
 
 from distutils.spawn import find_executable
 from distutils.spawn import spawn
@@ -44,9 +44,9 @@ def test_spawn(self):
         spawn([exe])  # should work without any error
 
     def test_find_executable(self):
-        with test_support.temp_dir() as tmp_dir:
+        with os_helper.temp_dir() as tmp_dir:
             # use TESTFN to get a pseudo-unique filename
-            program_noeext = test_support.TESTFN
+            program_noeext = os_helper.TESTFN
             # Give the temporary program an ".exe" suffix for all.
             # It's needed on Windows and not harmful on other platforms.
             program = program_noeext + ".exe"
@@ -66,7 +66,7 @@ def test_find_executable(self):
                 self.assertEqual(rv, filename)
 
             # test find in the current directory
-            with test_support.change_cwd(tmp_dir):
+            with os_helper.change_cwd(tmp_dir):
                 rv = find_executable(program)
                 self.assertEqual(rv, program)
 
@@ -76,7 +76,7 @@ def test_find_executable(self):
             self.assertIsNone(rv)
 
             # PATH='': no match, except in the current directory
-            with test_support.EnvironmentVarGuard() as env:
+            with os_helper.EnvironmentVarGuard() as env:
                 env['PATH'] = ''
                 with unittest.mock.patch('distutils.spawn.os.confstr',
                                          return_value=tmp_dir, create=True), \
@@ -86,12 +86,12 @@ def test_find_executable(self):
                     self.assertIsNone(rv)
 
                     # look in current directory
-                    with test_support.change_cwd(tmp_dir):
+                    with os_helper.change_cwd(tmp_dir):
                         rv = find_executable(program)
                         self.assertEqual(rv, program)
 
             # PATH=':': explicitly looks in the current directory
-            with test_support.EnvironmentVarGuard() as env:
+            with os_helper.EnvironmentVarGuard() as env:
                 env['PATH'] = os.pathsep
                 with unittest.mock.patch('distutils.spawn.os.confstr',
                                          return_value='', create=True), \
@@ -100,12 +100,12 @@ def test_find_executable(self):
                     self.assertIsNone(rv)
 
                     # look in current directory
-                    with test_support.change_cwd(tmp_dir):
+                    with os_helper.change_cwd(tmp_dir):
                         rv = find_executable(program)
                         self.assertEqual(rv, program)
 
             # missing PATH: test os.confstr("CS_PATH") and os.defpath
-            with test_support.EnvironmentVarGuard() as env:
+            with os_helper.EnvironmentVarGuard() as env:
                 env.pop('PATH', None)
 
                 # without confstr
diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py
index f1c7d34085c5e..078bf0e9b9270 100644
--- a/Lib/test/test_dbm_gnu.py
+++ b/Lib/test/test_dbm_gnu.py
@@ -1,5 +1,6 @@
 from test import support
-gdbm = support.import_module("dbm.gnu") #skip if not supported
+from test.support import import_helper
+gdbm = import_helper.import_module("dbm.gnu") #skip if not supported
 import unittest
 import os
 from test.support import TESTFN, TESTFN_NONASCII, unlink
diff --git a/Lib/test/test_eof.py b/Lib/test/test_eof.py
index 51cbbd8eed664..2cf263d27463c 100644
--- a/Lib/test/test_eof.py
+++ b/Lib/test/test_eof.py
@@ -2,6 +2,7 @@
 
 import sys
 from test import support
+from test.support import os_helper
 from test.support import script_helper
 import unittest
 
@@ -48,7 +49,7 @@ def test_line_continuation_EOF(self):
     @unittest.skipIf(not sys.executable, "sys.executable required")
     def test_line_continuation_EOF_from_file_bpo2180(self):
         """Ensure tok_nextc() does not add too many ending newlines."""
-        with support.temp_dir() as temp_dir:
+        with os_helper.temp_dir() as temp_dir:
             file_name = script_helper.make_script(temp_dir, 'foo', '\\')
             rc, out, err = script_helper.assert_python_failure(file_name)
             self.assertIn(b'unexpected EOF while parsing', err)
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index ba902986adb81..4551011f5ca9e 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -18,7 +18,8 @@
 import unittest
 import warnings
 from test import support
-from test.support import _4G, bigmemtest, import_fresh_module
+from test.support import _4G, bigmemtest
+from test.support.import_helper import import_fresh_module
 from test.support import threading_helper
 from http.client import HTTPException
 
diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py
index 8bc01deaa3384..b205d35649860 100644
--- a/Lib/test/test_idle.py
+++ b/Lib/test/test_idle.py
@@ -1,5 +1,5 @@
 import unittest
-from test.support import import_module
+from test.support.import_helper import import_module
 
 # Skip test_idle if _tkinter wasn't built, if tkinter is missing,
 # if tcl/tk is not the 8.5+ needed for ttk widgets,
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index b8ab677e6f6a9..96bcb09261e9e 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -14,6 +14,7 @@
                           run_with_tz, run_with_locale, cpython_only)
 from test.support import hashlib_helper
 from test.support import threading_helper
+from test.support import warnings_helper
 import unittest
 from unittest import mock
 from datetime import datetime, timezone, timedelta
@@ -575,7 +576,7 @@ def test_ssl_verified(self):
     # to CPython stdlib
     @cpython_only
     def test_certfile_arg_warn(self):
-        with support.check_warnings(('', DeprecationWarning)):
+        with warnings_helper.check_warnings(('', DeprecationWarning)):
             with mock.patch.object(self.imap_class, 'open'):
                 with mock.patch.object(self.imap_class, '_connect'):
                     self.imap_class('localhost', 143, certfile=CERTFILE)
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index b7f4dbb98e36d..7bcf8e8399a81 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -1,4 +1,5 @@
 from test import support
+from test.support import os_helper
 import array
 import io
 import marshal
@@ -17,13 +18,13 @@ def helper(self, sample, *extra):
         new = marshal.loads(marshal.dumps(sample, *extra))
         self.assertEqual(sample, new)
         try:
-            with open(support.TESTFN, "wb") as f:
+            with open(os_helper.TESTFN, "wb") as f:
                 marshal.dump(sample, f, *extra)
-            with open(support.TESTFN, "rb") as f:
+            with open(os_helper.TESTFN, "rb") as f:
                 new = marshal.load(f)
             self.assertEqual(sample, new)
         finally:
-            support.unlink(support.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
 
 class IntTestCase(unittest.TestCase, HelperMixin):
     def test_ints(self):
@@ -281,20 +282,20 @@ def test_multiple_dumps_and_loads(self):
             ilen = len(interleaved)
             positions = []
             try:
-                with open(support.TESTFN, 'wb') as f:
+                with open(os_helper.TESTFN, 'wb') as f:
                     for d in data:
                         marshal.dump(d, f)
                         if ilen:
                             f.write(interleaved)
                         positions.append(f.tell())
-                with open(support.TESTFN, 'rb') as f:
+                with open(os_helper.TESTFN, 'rb') as f:
                     for i, d in enumerate(data):
                         self.assertEqual(d, marshal.load(f))
                         if ilen:
                             f.read(ilen)
                         self.assertEqual(positions[i], f.tell())
             finally:
-                support.unlink(support.TESTFN)
+                os_helper.unlink(os_helper.TESTFN)
 
     def test_loads_reject_unicode_strings(self):
         # Issue #14177: marshal.loads() should not accept unicode strings
@@ -516,81 +517,81 @@ class CAPI_TestCase(unittest.TestCase, HelperMixin):
 
     def test_write_long_to_file(self):
         for v in range(marshal.version + 1):
-            _testcapi.pymarshal_write_long_to_file(0x12345678, support.TESTFN, v)
-            with open(support.TESTFN, 'rb') as f:
+            _testcapi.pymarshal_write_long_to_file(0x12345678, os_helper.TESTFN, v)
+            with open(os_helper.TESTFN, 'rb') as f:
                 data = f.read()
-            support.unlink(support.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
             self.assertEqual(data, b'\x78\x56\x34\x12')
 
     def test_write_object_to_file(self):
         obj = ('\u20ac', b'abc', 123, 45.6, 7+8j, 'long line '*1000)
         for v in range(marshal.version + 1):
-            _testcapi.pymarshal_write_object_to_file(obj, support.TESTFN, v)
-            with open(support.TESTFN, 'rb') as f:
+            _testcapi.pymarshal_write_object_to_file(obj, os_helper.TESTFN, v)
+            with open(os_helper.TESTFN, 'rb') as f:
                 data = f.read()
-            support.unlink(support.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
             self.assertEqual(marshal.loads(data), obj)
 
     def test_read_short_from_file(self):
-        with open(support.TESTFN, 'wb') as f:
+        with open(os_helper.TESTFN, 'wb') as f:
             f.write(b'\x34\x12xxxx')
-        r, p = _testcapi.pymarshal_read_short_from_file(support.TESTFN)
-        support.unlink(support.TESTFN)
+        r, p = _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
+        os_helper.unlink(os_helper.TESTFN)
         self.assertEqual(r, 0x1234)
         self.assertEqual(p, 2)
 
-        with open(support.TESTFN, 'wb') as f:
+        with open(os_helper.TESTFN, 'wb') as f:
             f.write(b'\x12')
         with self.assertRaises(EOFError):
-            _testcapi.pymarshal_read_short_from_file(support.TESTFN)
-        support.unlink(support.TESTFN)
+            _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
+        os_helper.unlink(os_helper.TESTFN)
 
     def test_read_long_from_file(self):
-        with open(support.TESTFN, 'wb') as f:
+        with open(os_helper.TESTFN, 'wb') as f:
             f.write(b'\x78\x56\x34\x12xxxx')
-        r, p = _testcapi.pymarshal_read_long_from_file(support.TESTFN)
-        support.unlink(support.TESTFN)
+        r, p = _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
+        os_helper.unlink(os_helper.TESTFN)
         self.assertEqual(r, 0x12345678)
         self.assertEqual(p, 4)
 
-        with open(support.TESTFN, 'wb') as f:
+        with open(os_helper.TESTFN, 'wb') as f:
             f.write(b'\x56\x34\x12')
         with self.assertRaises(EOFError):
-            _testcapi.pymarshal_read_long_from_file(support.TESTFN)
-        support.unlink(support.TESTFN)
+            _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
+        os_helper.unlink(os_helper.TESTFN)
 
     def test_read_last_object_from_file(self):
         obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
         for v in range(marshal.version + 1):
             data = marshal.dumps(obj, v)
-            with open(support.TESTFN, 'wb') as f:
+            with open(os_helper.TESTFN, 'wb') as f:
                 f.write(data + b'xxxx')
-            r, p = _testcapi.pymarshal_read_last_object_from_file(support.TESTFN)
-            support.unlink(support.TESTFN)
+            r, p = _testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
             self.assertEqual(r, obj)
 
-            with open(support.TESTFN, 'wb') as f:
+            with open(os_helper.TESTFN, 'wb') as f:
                 f.write(data[:1])
             with self.assertRaises(EOFError):
-                _testcapi.pymarshal_read_last_object_from_file(support.TESTFN)
-            support.unlink(support.TESTFN)
+                _testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
 
     def test_read_object_from_file(self):
         obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
         for v in range(marshal.version + 1):
             data = marshal.dumps(obj, v)
-            with open(support.TESTFN, 'wb') as f:
+            with open(os_helper.TESTFN, 'wb') as f:
                 f.write(data + b'xxxx')
-            r, p = _testcapi.pymarshal_read_object_from_file(support.TESTFN)
-            support.unlink(support.TESTFN)
+            r, p = _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
             self.assertEqual(r, obj)
             self.assertEqual(p, len(data))
 
-            with open(support.TESTFN, 'wb') as f:
+            with open(os_helper.TESTFN, 'wb') as f:
                 f.write(data[:1])
             with self.assertRaises(EOFError):
-                _testcapi.pymarshal_read_object_from_file(support.TESTFN)
-            support.unlink(support.TESTFN)
+                _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
+            os_helper.unlink(os_helper.TESTFN)
 
 
 if __name__ == "__main__":
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
index 11b579c26e711..d8ba009ea8482 100644
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -102,7 +102,7 @@ def test_cache_path(self):
         self.assertTrue(os.path.exists(self.cache_path))
 
     def test_cwd(self):
-        with support.change_cwd(self.directory):
+        with os_helper.change_cwd(self.directory):
             py_compile.compile(os.path.basename(self.source_path),
                                os.path.basename(self.pyc_path))
         self.assertTrue(os.path.exists(self.pyc_path))
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 68d494213e587..e45f018d2da71 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -1,5 +1,6 @@
 import unittest
 from test import support
+from test.support import warnings_helper
 import gc
 import weakref
 import operator
@@ -953,7 +954,7 @@ def test_repr(self):
 
 class TestBasicOpsMixedStringBytes(TestBasicOps, unittest.TestCase):
     def setUp(self):
-        self._warning_filters = support.check_warnings()
+        self._warning_filters = warnings_helper.check_warnings()
         self._warning_filters.__enter__()
         warnings.simplefilter('ignore', BytesWarning)
         self.case   = "string and bytes set"
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index cff07b46c7a2a..67ac045330f3e 100755
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1,5 +1,6 @@
 import unittest
 from test import support
+from test.support import os_helper
 from test.support import socket_helper
 from test.support import threading_helper
 
@@ -697,7 +698,7 @@ def setUp(self):
     def bindSock(self, sock):
         path = tempfile.mktemp(dir=self.dir_path)
         socket_helper.bind_unix_socket(sock, path)
-        self.addCleanup(support.unlink, path)
+        self.addCleanup(os_helper.unlink, path)
 
 class UnixStreamBase(UnixSocketTestBase):
     """Base class for Unix-domain SOCK_STREAM tests."""
@@ -1917,14 +1918,14 @@ def test_socket_fileno_rejects_negative(self):
     def test_socket_fileno_requires_valid_fd(self):
         WSAENOTSOCK = 10038
         with self.assertRaises(OSError) as cm:
-            socket.socket(fileno=support.make_bad_fd())
+            socket.socket(fileno=os_helper.make_bad_fd())
         self.assertIn(cm.exception.errno, (errno.EBADF, WSAENOTSOCK))
 
         with self.assertRaises(OSError) as cm:
             socket.socket(
                 socket.AF_INET,
                 socket.SOCK_STREAM,
-                fileno=support.make_bad_fd())
+                fileno=os_helper.make_bad_fd())
         self.assertIn(cm.exception.errno, (errno.EBADF, WSAENOTSOCK))
 
     def test_socket_fileno_requires_socket_fd(self):
@@ -5458,35 +5459,35 @@ def testUnbound(self):
 
     def testStrAddr(self):
         # Test binding to and retrieving a normal string pathname.
-        path = os.path.abspath(support.TESTFN)
+        path = os.path.abspath(os_helper.TESTFN)
         self.bind(self.sock, path)
-        self.addCleanup(support.unlink, path)
+        self.addCleanup(os_helper.unlink, path)
         self.assertEqual(self.sock.getsockname(), path)
 
     def testBytesAddr(self):
         # Test binding to a bytes pathname.
-        path = os.path.abspath(support.TESTFN)
+        path = os.path.abspath(os_helper.TESTFN)
         self.bind(self.sock, self.encoded(path))
-        self.addCleanup(support.unlink, path)
+        self.addCleanup(os_helper.unlink, path)
         self.assertEqual(self.sock.getsockname(), path)
 
     def testSurrogateescapeBind(self):
         # Test binding to a valid non-ASCII pathname, with the
         # non-ASCII bytes supplied using surrogateescape encoding.
-        path = os.path.abspath(support.TESTFN_UNICODE)
+        path = os.path.abspath(os_helper.TESTFN_UNICODE)
         b = self.encoded(path)
         self.bind(self.sock, b.decode("ascii", "surrogateescape"))
-        self.addCleanup(support.unlink, path)
+        self.addCleanup(os_helper.unlink, path)
         self.assertEqual(self.sock.getsockname(), path)
 
     def testUnencodableAddr(self):
         # Test binding to a pathname that cannot be encoded in the
         # file system encoding.
-        if support.TESTFN_UNENCODABLE is None:
+        if os_helper.TESTFN_UNENCODABLE is None:
             self.skipTest("No unencodable filename available")
-        path = os.path.abspath(support.TESTFN_UNENCODABLE)
+        path = os.path.abspath(os_helper.TESTFN_UNENCODABLE)
         self.bind(self.sock, path)
-        self.addCleanup(support.unlink, path)
+        self.addCleanup(os_helper.unlink, path)
         self.assertEqual(self.sock.getsockname(), path)
 
 
@@ -5960,16 +5961,16 @@ def chunks(total, step):
 
         chunk = b"".join([random.choice(string.ascii_letters).encode()
                           for i in range(cls.BUFSIZE)])
-        with open(support.TESTFN, 'wb') as f:
+        with open(os_helper.TESTFN, 'wb') as f:
             for csize in chunks(cls.FILESIZE, cls.BUFSIZE):
                 f.write(chunk)
-        with open(support.TESTFN, 'rb') as f:
+        with open(os_helper.TESTFN, 'rb') as f:
             cls.FILEDATA = f.read()
             assert len(cls.FILEDATA) == cls.FILESIZE
 
     @classmethod
     def tearDownClass(cls):
-        support.unlink(support.TESTFN)
+        os_helper.unlink(os_helper.TESTFN)
 
     def accept_conn(self):
         self.serv.settimeout(support.LONG_TIMEOUT)
@@ -5996,7 +5997,7 @@ def meth_from_sock(self, sock):
 
     def _testRegularFile(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         with socket.create_connection(address) as sock, file as file:
             meth = self.meth_from_sock(sock)
             sent = meth(file)
@@ -6031,9 +6032,9 @@ def testNonRegularFile(self):
 
     def _testEmptyFileSend(self):
         address = self.serv.getsockname()
-        filename = support.TESTFN + "2"
+        filename = os_helper.TESTFN + "2"
         with open(filename, 'wb'):
-            self.addCleanup(support.unlink, filename)
+            self.addCleanup(os_helper.unlink, filename)
         file = open(filename, 'rb')
         with socket.create_connection(address) as sock, file as file:
             meth = self.meth_from_sock(sock)
@@ -6050,7 +6051,7 @@ def testEmptyFileSend(self):
 
     def _testOffset(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         with socket.create_connection(address) as sock, file as file:
             meth = self.meth_from_sock(sock)
             sent = meth(file, offset=5000)
@@ -6067,7 +6068,7 @@ def testOffset(self):
 
     def _testCount(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         sock = socket.create_connection(address,
                                         timeout=support.LOOPBACK_TIMEOUT)
         with sock, file:
@@ -6088,7 +6089,7 @@ def testCount(self):
 
     def _testCountSmall(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         sock = socket.create_connection(address,
                                         timeout=support.LOOPBACK_TIMEOUT)
         with sock, file:
@@ -6109,7 +6110,7 @@ def testCountSmall(self):
 
     def _testCountWithOffset(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         with socket.create_connection(address, timeout=2) as sock, file as file:
             count = 100007
             meth = self.meth_from_sock(sock)
@@ -6128,7 +6129,7 @@ def testCountWithOffset(self):
 
     def _testNonBlocking(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         with socket.create_connection(address) as sock, file as file:
             sock.setblocking(False)
             meth = self.meth_from_sock(sock)
@@ -6144,7 +6145,7 @@ def testNonBlocking(self):
 
     def _testWithTimeout(self):
         address = self.serv.getsockname()
-        file = open(support.TESTFN, 'rb')
+        file = open(os_helper.TESTFN, 'rb')
         sock = socket.create_connection(address,
                                         timeout=support.LOOPBACK_TIMEOUT)
         with sock, file:
@@ -6162,7 +6163,7 @@ def testWithTimeout(self):
 
     def _testWithTimeoutTriggeredSend(self):
         address = self.serv.getsockname()
-        with open(support.TESTFN, 'rb') as file:
+        with open(os_helper.TESTFN, 'rb') as file:
             with socket.create_connection(address) as sock:
                 sock.settimeout(0.01)
                 meth = self.meth_from_sock(sock)
@@ -6178,17 +6179,17 @@ def _test_errors(self):
         pass
 
     def test_errors(self):
-        with open(support.TESTFN, 'rb') as file:
+        with open(os_helper.TESTFN, 'rb') as file:
             with socket.socket(type=socket.SOCK_DGRAM) as s:
                 meth = self.meth_from_sock(s)
                 self.assertRaisesRegex(
                     ValueError, "SOCK_STREAM", meth, file)
-        with open(support.TESTFN, 'rt') as file:
+        with open(os_helper.TESTFN, 'rt') as file:
             with socket.socket() as s:
                 meth = self.meth_from_sock(s)
                 self.assertRaisesRegex(
                     ValueError, "binary mode", meth, file)
-        with open(support.TESTFN, 'rb') as file:
+        with open(os_helper.TESTFN, 'rb') as file:
             with socket.socket() as s:
                 meth = self.meth_from_sock(s)
                 self.assertRaisesRegex(TypeError, "positive integer",
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index 44e44bf5ea995..d07d28df607ce 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -5,9 +5,11 @@
 import shutil
 from copy import copy
 
-from test.support import (import_module, TESTFN, unlink, check_warnings,
-                          captured_stdout, skip_unless_symlink, change_cwd,
-                          PythonSymlink)
+from test.support import (captured_stdout, PythonSymlink)
+from test.support.import_helper import import_module
+from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
+                                    change_cwd)
+from test.support.warnings_helper import check_warnings
 
 import sysconfig
 from sysconfig import (get_paths, get_platform, get_config_vars,
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 925a6bc32e8ea..c5fbd8700ae9b 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -7,7 +7,8 @@
 import unittest
 import re
 from test import support
-from test.support import TESTFN, Error, captured_output, unlink, cpython_only, ALWAYS_EQ
+from test.support import Error, captured_output, cpython_only, ALWAYS_EQ
+from test.support.os_helper import TESTFN, unlink
 from test.support.script_helper import assert_python_ok
 import textwrap
 
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 59697935fe5cd..afc95555db026 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -15,6 +15,8 @@
 import unicodedata
 import unittest
 import warnings
+from test.support import import_helper
+from test.support import warnings_helper
 from test import support, string_tests
 from test.support.script_helper import assert_python_failure
 
@@ -504,7 +506,7 @@ def test_replace_id(self):
         self.assertIs(text.replace(pattern, pattern), text)
 
     def test_bytes_comparison(self):
-        with support.check_warnings():
+        with warnings_helper.check_warnings():
             warnings.simplefilter('ignore', BytesWarning)
             self.assertEqual('abc' == b'abc', False)
             self.assertEqual('abc' != b'abc', True)
@@ -725,7 +727,7 @@ def test_isidentifier_legacy(self):
         import _testcapi
         u = '𝖀𝖓𝖎𝖈𝖔𝖉𝖊'
         self.assertTrue(u.isidentifier())
-        with support.check_warnings():
+        with warnings_helper.check_warnings():
             warnings.simplefilter('ignore', DeprecationWarning)
             self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier())
 
@@ -2507,7 +2509,7 @@ class CAPITest(unittest.TestCase):
 
     # Test PyUnicode_FromFormat()
     def test_from_format(self):
-        support.import_module('ctypes')
+        import_helper.import_module('ctypes')
         from ctypes import (
             pythonapi, py_object, sizeof,
             c_int, c_long, c_longlong, c_ssize_t,
@@ -2748,7 +2750,7 @@ def check_format(expected, format, *args):
     @support.cpython_only
     def test_aswidechar(self):
         from _testcapi import unicode_aswidechar
-        support.import_module('ctypes')
+        import_helper.import_module('ctypes')
         from ctypes import c_wchar, sizeof
 
         wchar, size = unicode_aswidechar('abcdef', 2)
@@ -2786,7 +2788,7 @@ def test_aswidechar(self):
     @support.cpython_only
     def test_aswidecharstring(self):
         from _testcapi import unicode_aswidecharstring
-        support.import_module('ctypes')
+        import_helper.import_module('ctypes')
         from ctypes import c_wchar, sizeof
 
         wchar, size = unicode_aswidecharstring('abc')
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index d01649d1c31b2..63f9b92a83de2 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -24,7 +24,12 @@
 from functools import partial
 from itertools import product, islice
 from test import support
-from test.support import TESTFN, findfile, import_fresh_module, gc_collect, swap_attr
+from test.support import os_helper
+from test.support import warnings_helper
+from test.support import findfile, gc_collect, swap_attr
+from test.support.import_helper import import_fresh_module
+from test.support.os_helper import TESTFN
+
 
 # pyET is the pure-Python implementation.
 #
@@ -601,7 +606,7 @@ def test_iterparse(self):
             self.assertFalse(f.closed)
         self.assertEqual(str(cm.exception), "unknown event 'bogus'")
 
-        with support.check_no_resource_warning(self):
+        with warnings_helper.check_no_resource_warning(self):
             with self.assertRaises(ValueError) as cm:
                 iterparse(SIMPLE_XMLFILE, events)
             self.assertEqual(str(cm.exception), "unknown event 'bogus'")
@@ -627,13 +632,13 @@ def test_iterparse(self):
         self.assertEqual(str(cm.exception),
                 'junk after document element: line 1, column 12')
 
-        self.addCleanup(support.unlink, TESTFN)
+        self.addCleanup(os_helper.unlink, TESTFN)
         with open(TESTFN, "wb") as f:
             f.write(b"<document />junk")
         it = iterparse(TESTFN)
         action, elem = next(it)
         self.assertEqual((action, elem.tag), ('end', 'document'))
-        with support.check_no_resource_warning(self):
+        with warnings_helper.check_no_resource_warning(self):
             with self.assertRaises(ET.ParseError) as cm:
                 next(it)
             self.assertEqual(str(cm.exception),
@@ -3641,14 +3646,14 @@ def test_encoding(self):
                      "<tag key=\"åöö<>\" />" % enc).encode(enc))
 
     def test_write_to_filename(self):
-        self.addCleanup(support.unlink, TESTFN)
+        self.addCleanup(os_helper.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         tree.write(TESTFN)
         with open(TESTFN, 'rb') as f:
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_text_file(self):
-        self.addCleanup(support.unlink, TESTFN)
+        self.addCleanup(os_helper.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         with open(TESTFN, 'w', encoding='utf-8') as f:
             tree.write(f, encoding='unicode')
@@ -3657,7 +3662,7 @@ def test_write_to_text_file(self):
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_binary_file(self):
-        self.addCleanup(support.unlink, TESTFN)
+        self.addCleanup(os_helper.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         with open(TESTFN, 'wb') as f:
             tree.write(f)
@@ -3666,7 +3671,7 @@ def test_write_to_binary_file(self):
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_binary_file_with_bom(self):
-        self.addCleanup(support.unlink, TESTFN)
+        self.addCleanup(os_helper.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         # test BOM writing to buffered file
         with open(TESTFN, 'wb') as f:
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index b7bc218d17a3d..2851051425bf1 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -19,9 +19,10 @@
 from random import randint, random, randbytes
 
 from test.support import script_helper
-from test.support import (TESTFN, findfile, unlink, rmtree, temp_dir, temp_cwd,
-                          requires_zlib, requires_bz2, requires_lzma,
-                          captured_stdout)
+from test.support import (findfile, requires_zlib, requires_bz2,
+                          requires_lzma, captured_stdout)
+from test.support.os_helper import TESTFN, unlink, rmtree, temp_dir, temp_cwd
+
 
 TESTFN2 = TESTFN + "2"
 TESTFNDIR = TESTFN + "d"



More information about the Python-checkins mailing list