Skip to content

Commit 7eebeb8

Browse files
authored
bpo-30812: Fix test_warnings, restore _showwarnmsg (#2504)
bpo-26568, bpo-30812: Fix test_showwarnmsg_missing(): restore the attribute after removing it.
1 parent e4f9a2d commit 7eebeb8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,15 @@ def test_showwarnmsg_missing(self):
727727
text = 'del _showwarnmsg test'
728728
with original_warnings.catch_warnings(module=self.module):
729729
self.module.filterwarnings("always", category=UserWarning)
730-
del self.module._showwarnmsg
731-
with support.captured_output('stderr') as stream:
732-
self.module.warn(text)
733-
result = stream.getvalue()
730+
731+
show = self.module._showwarnmsg
732+
try:
733+
del self.module._showwarnmsg
734+
with support.captured_output('stderr') as stream:
735+
self.module.warn(text)
736+
result = stream.getvalue()
737+
finally:
738+
self.module._showwarnmsg = show
734739
self.assertIn(text, result)
735740

736741
def test_showwarning_not_callable(self):

0 commit comments

Comments
 (0)