[3.9] bpo-44852: Support ignoring specific DeprecationWarnings wholesale in regrtest (GH-27634) (GH-27785)

(cherry picked from commit a0a6d39295)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Łukasz Langa 2021-08-16 22:47:08 +02:00 committed by GitHub
parent 43bab0537c
commit c7c4cbc58e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 269 additions and 0 deletions

View file

@ -11,6 +11,8 @@ import tempfile
import textwrap
import time
import unittest
import warnings
from test import support
from test.support import script_helper
from test.support import socket_helper
@ -19,6 +21,33 @@ TESTFN = support.TESTFN
class TestSupport(unittest.TestCase):
@classmethod
def setUpClass(cls):
orig_filter_len = len(warnings.filters)
cls._warnings_helper_token = support.ignore_deprecations_from(
"test.test_support", like=".*used in test_support.*"
)
cls._test_support_token = support.ignore_deprecations_from(
"test.test_support", like=".*You should NOT be seeing this.*"
)
assert len(warnings.filters) == orig_filter_len + 2
@classmethod
def tearDownClass(cls):
orig_filter_len = len(warnings.filters)
support.clear_ignored_deprecations(
cls._warnings_helper_token,
cls._test_support_token,
)
assert len(warnings.filters) == orig_filter_len - 2
def test_ignored_deprecations_are_silent(self):
"""Test support.ignore_deprecations_from() silences warnings"""
with warnings.catch_warnings(record=True) as warning_objs:
_warn_about_deprecation()
warnings.warn("You should NOT be seeing this.", DeprecationWarning)
messages = [str(w.message) for w in warning_objs]
self.assertEqual(len(messages), 0, messages)
def test_import_module(self):
support.import_module("ftplib")
@ -676,6 +705,17 @@ class TestSupport(unittest.TestCase):
# SuppressCrashReport
def _warn_about_deprecation():
# In 3.10+ this lives in test.support.warnings_helper
warnings.warn(
"This is used in test_support test to ensure"
" support.ignore_deprecations_from() works as expected."
" You should not be seeing this.",
DeprecationWarning,
stacklevel=0,
)
def test_main():
tests = [TestSupport]
support.run_unittest(*tests)