Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 96d4943

Browse files
committed
Reapplied change to test_warnings.py to test_warnings/__init__.py.
1 parent f35bd30 commit 96d4943

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class BaseTest:
4444
"""Basic bookkeeping required for testing."""
4545

4646
def setUp(self):
47+
self.old_unittest_module = unittest.case.warnings
4748
# The __warningregistry__ needs to be in a pristine state for tests
4849
# to work properly.
4950
if '__warningregistry__' in globals():
@@ -55,10 +56,15 @@ def setUp(self):
5556
# The 'warnings' module must be explicitly set so that the proper
5657
# interaction between _warnings and 'warnings' can be controlled.
5758
sys.modules['warnings'] = self.module
59+
# Ensure that unittest.TestCase.assertWarns() uses the same warnings
60+
# module than warnings.catch_warnings(). Otherwise,
61+
# warnings.catch_warnings() will be unable to remove the added filter.
62+
unittest.case.warnings = self.module
5863
super(BaseTest, self).setUp()
5964

6065
def tearDown(self):
6166
sys.modules['warnings'] = original_warnings
67+
unittest.case.warnings = self.old_unittest_module
6268
super(BaseTest, self).tearDown()
6369

6470
class PublicAPITests(BaseTest):

0 commit comments

Comments
 (0)