[Python-checkins] gh-92169: Use warnings_helper.import_deprecated() to import deprecated modules uniformly in tests (GH-92170)

serhiy-storchaka webhook-mailer at python.org
Tue May 3 03:18:06 EDT 2022


https://github.com/python/cpython/commit/9b027d4cea57e98c76f5176cc3188dc81603356c
commit: 9b027d4cea57e98c76f5176cc3188dc81603356c
branch: main
author: Hugo van Kemenade <hugovk at users.noreply.github.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022-05-03T10:17:54+03:00
summary:

gh-92169: Use warnings_helper.import_deprecated() to import deprecated modules uniformly in tests (GH-92170)

files:
A Misc/NEWS.d/next/Tests/2022-05-02-20-57-04.gh-issue-92169.Xi4NGV.rst
M Lib/test/test_asynchat.py
M Lib/test/test_asyncore.py
M Lib/test/test_ftplib.py
M Lib/test/test_imp.py
M Lib/test/test_logging.py
M Lib/test/test_poplib.py
M Lib/test/test_smtpd.py
M Lib/test/test_smtplib.py
M Lib/test/test_ssl.py

diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index d28d67732e788..9d08bd02968fd 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -3,6 +3,7 @@
 from test import support
 from test.support import socket_helper
 from test.support import threading_helper
+from test.support import warnings_helper
 
 import errno
 import socket
@@ -12,11 +13,9 @@
 import unittest
 import unittest.mock
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asynchat
-    import asyncore
+
+asynchat = warnings_helper.import_deprecated('asynchat')
+asyncore = warnings_helper.import_deprecated('asyncore')
 
 support.requires_working_socket(module=True)
 
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index e3f31bd06d0c3..98ccd3a9304de 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -20,10 +20,7 @@
 
 support.requires_working_socket(module=True)
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asyncore
+asyncore = warnings_helper.import_deprecated('asyncore')
 
 
 HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX')
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 2794fccfe7c72..082a90d46baed 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -23,11 +23,10 @@
 from test.support import warnings_helper
 from test.support.socket_helper import HOST, HOSTv6
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asyncore
-    import asynchat
+
+asynchat = warnings_helper.import_deprecated('asynchat')
+asyncore = warnings_helper.import_deprecated('asyncore')
+
 
 support.requires_working_socket(module=True)
 
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 35e9a2a186552..d44dc6b49f293 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -8,11 +8,10 @@
 from test.support import import_helper
 from test.support import os_helper
 from test.support import script_helper
+from test.support import warnings_helper
 import unittest
 import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import imp
+imp = warnings_helper.import_deprecated('imp')
 import _imp
 
 
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 7555f05d1d0cf..5d4ddedd059fc 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -60,10 +60,10 @@
 from socketserver import (ThreadingUDPServer, DatagramRequestHandler,
                           ThreadingTCPServer, StreamRequestHandler)
 
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asyncore
-    import smtpd
+
+asyncore = warnings_helper.import_deprecated('asyncore')
+smtpd = warnings_helper.import_deprecated('smtpd')
+
 
 try:
     import win32evtlog, win32evtlogutil, pywintypes
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 57ccc541b81fe..5ad9202433dcf 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -15,12 +15,12 @@
 from test.support import hashlib_helper
 from test.support import socket_helper
 from test.support import threading_helper
+from test.support import warnings_helper
+
+
+asynchat = warnings_helper.import_deprecated('asynchat')
+asyncore = warnings_helper.import_deprecated('asyncore')
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asynchat
-    import asyncore
 
 test_support.requires_working_socket(module=True)
 
diff --git a/Lib/test/test_smtpd.py b/Lib/test/test_smtpd.py
index d2e150d535ff6..57eb98ebc1d1e 100644
--- a/Lib/test/test_smtpd.py
+++ b/Lib/test/test_smtpd.py
@@ -6,11 +6,9 @@
 import socket
 import io
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import smtpd
-    import asyncore
+
+smtpd = warnings_helper.import_deprecated('smtpd')
+asyncore = warnings_helper.import_deprecated('asyncore')
 
 
 class DummyServer(smtpd.SMTPServer):
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index e798645a5ca66..a4074c02f1926 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -21,13 +21,13 @@
 from test.support import hashlib_helper
 from test.support import socket_helper
 from test.support import threading_helper
+from test.support import warnings_helper
 from unittest.mock import Mock
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asyncore
-    import smtpd
+
+asyncore = warnings_helper.import_deprecated('asyncore')
+smtpd = warnings_helper.import_deprecated('smtpd')
+
 
 support.requires_working_socket(module=True)
 
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 543d34a546933..0eb8d18b3561e 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -12,7 +12,6 @@
 import socket
 import select
 import time
-import datetime
 import enum
 import gc
 import os
@@ -30,10 +29,9 @@
 except ImportError:
     ctypes = None
 
-import warnings
-with warnings.catch_warnings():
-    warnings.simplefilter('ignore', DeprecationWarning)
-    import asyncore
+
+asyncore = warnings_helper.import_deprecated('asyncore')
+
 
 ssl = import_helper.import_module("ssl")
 import _ssl
diff --git a/Misc/NEWS.d/next/Tests/2022-05-02-20-57-04.gh-issue-92169.Xi4NGV.rst b/Misc/NEWS.d/next/Tests/2022-05-02-20-57-04.gh-issue-92169.Xi4NGV.rst
new file mode 100644
index 0000000000000..3809ed4f5a1a1
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-05-02-20-57-04.gh-issue-92169.Xi4NGV.rst
@@ -0,0 +1,2 @@
+Use ``warnings_helper.import_deprecated()`` to import deprecated modules
+uniformly in tests. Patch by Hugo van Kemenade.



More information about the Python-checkins mailing list