[Python-checkins] r70975 - in python/trunk: Lib/test/test_logging.py Misc/NEWS

brett.cannon python-checkins at python.org
Wed Apr 1 21:57:10 CEST 2009


Author: brett.cannon
Date: Wed Apr  1 21:57:10 2009
New Revision: 70975

Log:
test_logging was blindly clearing the warnings filter. This caused
PendingDeprecationWarnings to be spewed all over by unittest.failIf*(). Fix
moves over to using warnings.catch_warning to protect the warnings filter.


Modified:
   python/trunk/Lib/test/test_logging.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/test/test_logging.py
==============================================================================
--- python/trunk/Lib/test/test_logging.py	(original)
+++ python/trunk/Lib/test/test_logging.py	Wed Apr  1 21:57:10 2009
@@ -910,30 +910,32 @@
 
 
 class WarningsTest(BaseTest):
+
     def test_warnings(self):
         logging.captureWarnings(True)
-        warnings.filterwarnings("always", category=UserWarning)
-        try:
-            file = cStringIO.StringIO()
-            h = logging.StreamHandler(file)
-            logger = logging.getLogger("py.warnings")
-            logger.addHandler(h)
-            warnings.warn("I'm warning you...")
-            logger.removeHandler(h)
-            s = file.getvalue()
-            h.close()
-            self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
-
-            #See if an explicit file uses the original implementation
-            file = cStringIO.StringIO()
-            warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, file,
-                                 "Dummy line")
-            s = file.getvalue()
-            file.close()
-            self.assertEqual(s, "dummy.py:42: UserWarning: Explicit\n  Dummy line\n")
-        finally:
-            warnings.resetwarnings()
-            logging.captureWarnings(False)
+        with warnings.catch_warnings():
+            warnings.filterwarnings("always", category=UserWarning)
+            try:
+                file = cStringIO.StringIO()
+                h = logging.StreamHandler(file)
+                logger = logging.getLogger("py.warnings")
+                logger.addHandler(h)
+                warnings.warn("I'm warning you...")
+                logger.removeHandler(h)
+                s = file.getvalue()
+                h.close()
+                self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
+
+                #See if an explicit file uses the original implementation
+                file = cStringIO.StringIO()
+                warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
+                                        file, "Dummy line")
+                s = file.getvalue()
+                file.close()
+                self.assertEqual(s,
+                        "dummy.py:42: UserWarning: Explicit\n  Dummy line\n")
+            finally:
+                logging.captureWarnings(False)
 
 # Set the locale to the platform-dependent default.  I have no idea
 # why the test does this, but in any case we save the current locale

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Apr  1 21:57:10 2009
@@ -730,6 +730,8 @@
 Tests
 -----
 
+- Fix test_logging to no longer reset the warnings filter.
+
 - Issue #5635: Fix running test_sys with tracing enabled.
 
 - regrtest no longer treats ImportError as equivalent to SkipTest.  Imports


More information about the Python-checkins mailing list