summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-04-01 20:01:47 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-04-01 20:01:47 (GMT)
commitdf8709d7b141c334ebacbf0e4380de7fd90d1276 (patch)
treebe5accd39de6a72431b77033a61605a3d49aa7fd
parent3f10a952f6056b6797e4187bcfa1a97c21d1b3bb (diff)
downloadcpython-df8709d7b141c334ebacbf0e4380de7fd90d1276.zip
cpython-df8709d7b141c334ebacbf0e4380de7fd90d1276.tar.gz
cpython-df8709d7b141c334ebacbf0e4380de7fd90d1276.tar.bz2
Merged revisions 70975 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70975 | brett.cannon | 2009-04-01 12:57:10 -0700 (Wed, 01 Apr 2009) | 4 lines 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. ........
-rw-r--r--Lib/test/test_logging.py46
1 files changed, 24 insertions, 22 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index a2ea0df..a4da5da 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -910,30 +910,32 @@ class EncodingTest(BaseTest):
class WarningsTest(BaseTest):
+
def test_warnings(self):
logging.captureWarnings(True)
- warnings.filterwarnings("always", category=UserWarning)
- try:
- file = io.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 = io.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 = io.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 = io.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