bpo-30812: Fix test_warnings, restore _showwarnmsg (#2504) (#2507)

bpo-26568, bpo-30812: Fix test_showwarnmsg_missing(): restore the
attribute after removing it.
(cherry picked from commit 7eebeb8fb8)
This commit is contained in:
Victor Stinner 2017-06-30 13:12:12 +02:00 committed by GitHub
parent 6f3cb059fd
commit d0aac5da59

View 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):