summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-30 10:58:46 (GMT)
committerGitHub <noreply@github.com>2017-06-30 10:58:46 (GMT)
commit7eebeb8fb84e2a9cb73903a08c59cf1d3b32cee0 (patch)
tree810b225b4f11a1c97e7c541a6174fd74bb773dc1 /Lib/test
parente4f9a2d2be42d5a2cdd624f8ed7cdf5028c5fbc3 (diff)
downloadcpython-7eebeb8fb84e2a9cb73903a08c59cf1d3b32cee0.zip
cpython-7eebeb8fb84e2a9cb73903a08c59cf1d3b32cee0.tar.gz
cpython-7eebeb8fb84e2a9cb73903a08c59cf1d3b32cee0.tar.bz2
bpo-30812: Fix test_warnings, restore _showwarnmsg (#2504)
bpo-26568, bpo-30812: Fix test_showwarnmsg_missing(): restore the attribute after removing it.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_warnings/__init__.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index 8fc5d3c..3481e9c 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -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):