]> granicus.if.org Git - python/commitdiff
test_warnings ironically had a single test that was not protecting the warnings
authorBrett Cannon <bcannon@gmail.com>
Wed, 1 Apr 2009 20:25:48 +0000 (20:25 +0000)
committerBrett Cannon <bcannon@gmail.com>
Wed, 1 Apr 2009 20:25:48 +0000 (20:25 +0000)
filter and was resetting it.

Lib/test/test_warnings.py
Misc/NEWS

index bc177ad9e7ce3e0cb7ee5fc4a2599a647e89eda8..bb2fb5ff25022fb539638b67bd1fa2d197b63b8e 100644 (file)
@@ -460,14 +460,14 @@ class _WarningsTests(BaseTest):
         self.failUnless(text in result)
 
     def test_showwarning_not_callable(self):
-        self.module.filterwarnings("always", category=UserWarning)
-        old_showwarning = self.module.showwarning
-        self.module.showwarning = 23
-        try:
-            self.assertRaises(TypeError, self.module.warn, "Warning!")
-        finally:
-            self.module.showwarning = old_showwarning
-            self.module.resetwarnings()
+        with original_warnings.catch_warnings(module=self.module):
+            self.module.filterwarnings("always", category=UserWarning)
+            old_showwarning = self.module.showwarning
+            self.module.showwarning = 23
+            try:
+                self.assertRaises(TypeError, self.module.warn, "Warning!")
+            finally:
+                self.module.showwarning = old_showwarning
 
     def test_show_warning_output(self):
         # With showarning() missing, make sure that output is okay.
index c4474522fbe71b1bd216ca6a30be9f218a7ebb11..08552bf31452c2ce2fe385d7e36e29746ce72cc7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -730,6 +730,8 @@ Extension Modules
 Tests
 -----
 
+- Fix test_warnings to no longer reset the warnings filter.
+
 - Fix test_logging to no longer reset the warnings filter.
 
 - Issue #5635: Fix running test_sys with tracing enabled.