diff options
author | Łukasz Langa <lukasz@langa.pl> | 2021-08-17 12:01:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 12:01:00 +0200 |
commit | bc98f981326d7cb30f939dedd04b91f378255d88 (patch) | |
tree | d4897d6c85fc9cc5626b91ec0f73d49b1c6ed62a /Lib/test/test_support.py | |
parent | 6f6648e436d02bce0e49ba82f4377c0d2f586f0f (diff) | |
download | cpython-git-bc98f981326d7cb30f939dedd04b91f378255d88.tar.gz |
[3.10] bpo-44852: Support ignoring specific DeprecationWarnings wholesale in regrtest (GH-27634) (GH-27784)
(cherry picked from commit a0a6d39295a30434b088f4b66439bf5ea21a3e4e)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index b1d3411a86..11ca0c2fb2 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -11,6 +11,8 @@ import tempfile import textwrap import time import unittest +import warnings + from test import support from test.support import import_helper from test.support import os_helper @@ -22,6 +24,33 @@ TESTFN = os_helper.TESTFN class TestSupport(unittest.TestCase): + @classmethod + def setUpClass(cls): + orig_filter_len = len(warnings.filters) + cls._warnings_helper_token = support.ignore_deprecations_from( + "test.support.warnings_helper", 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: + warnings_helper._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): import_helper.import_module("ftplib") |