diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-04-01 19:57:10 +0000 |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-04-01 19:57:10 +0000 |
commit | 2da4d628a5100627876a55e6a911d59570cd8c69 (patch) | |
tree | 15deb3c743d5d2f5913ecac815d68b171823811c /Lib/test/test_logging.py | |
parent | 66c4a6b51cea40215e8f61e1abe2e3d89c4aeb1e (diff) | |
download | cpython-git-2da4d628a5100627876a55e6a911d59570cd8c69.tar.gz |
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.
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 9c7bf5bcfb..515fee9d0e 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 = 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 |