|
11 | 11 | import textwrap |
12 | 12 | import time |
13 | 13 | import unittest |
| 14 | +import warnings |
| 15 | + |
14 | 16 | from test import support |
15 | 17 | from test.support import import_helper |
16 | 18 | from test.support import os_helper |
|
22 | 24 |
|
23 | 25 |
|
24 | 26 | class TestSupport(unittest.TestCase): |
| 27 | + @classmethod |
| 28 | + def setUpClass(cls): |
| 29 | + orig_filter_len = len(warnings.filters) |
| 30 | + cls._warnings_helper_token = support.ignore_deprecations_from( |
| 31 | + "test.support.warnings_helper", like=".*used in test_support.*" |
| 32 | + ) |
| 33 | + cls._test_support_token = support.ignore_deprecations_from( |
| 34 | + "test.test_support", like=".*You should NOT be seeing this.*" |
| 35 | + ) |
| 36 | + assert len(warnings.filters) == orig_filter_len + 2 |
| 37 | + |
| 38 | + @classmethod |
| 39 | + def tearDownClass(cls): |
| 40 | + orig_filter_len = len(warnings.filters) |
| 41 | + support.clear_ignored_deprecations( |
| 42 | + cls._warnings_helper_token, |
| 43 | + cls._test_support_token, |
| 44 | + ) |
| 45 | + assert len(warnings.filters) == orig_filter_len - 2 |
| 46 | + |
| 47 | + def test_ignored_deprecations_are_silent(self): |
| 48 | + """Test support.ignore_deprecations_from() silences warnings""" |
| 49 | + with warnings.catch_warnings(record=True) as warning_objs: |
| 50 | + warnings_helper._warn_about_deprecation() |
| 51 | + warnings.warn("You should NOT be seeing this.", DeprecationWarning) |
| 52 | + messages = [str(w.message) for w in warning_objs] |
| 53 | + self.assertEqual(len(messages), 0, messages) |
25 | 54 |
|
26 | 55 | def test_import_module(self): |
27 | 56 | import_helper.import_module("ftplib") |
|
0 commit comments