]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30812: Fix test_warnings, restore _showwarnmsg (#2504)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 30 Jun 2017 10:58:46 +0000 (12:58 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Jun 2017 10:58:46 +0000 (12:58 +0200)
bpo-26568, bpo-30812: Fix test_showwarnmsg_missing(): restore the
attribute after removing it.

Lib/test/test_warnings/__init__.py

index 8fc5d3c5625bc1f77cf71b88c6a1ca709355e665..3481e9cb96869671555bbc1065b508576a2dd03e 100644 (file)
@@ -727,10 +727,15 @@ class _WarningsTests(BaseTest, unittest.TestCase):
         text = 'del _showwarnmsg test'
         with original_warnings.catch_warnings(module=self.module):
             self.module.filterwarnings("always", category=UserWarning)
-            del self.module._showwarnmsg
-            with support.captured_output('stderr') as stream:
-                self.module.warn(text)
-                result = stream.getvalue()
+
+            show = self.module._showwarnmsg
+            try:
+                del self.module._showwarnmsg
+                with support.captured_output('stderr') as stream:
+                    self.module.warn(text)
+                    result = stream.getvalue()
+            finally:
+                self.module._showwarnmsg = show
         self.assertIn(text, result)
 
     def test_showwarning_not_callable(self):