File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
6470class PublicAPITests (BaseTest ):
You can’t perform that action at this time.
0 commit comments