diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-06-30 11:12:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-30 11:12:12 (GMT) |
commit | d0aac5da59b1bbd113e6081d7c807ad5bced8a05 (patch) | |
tree | 26d40e2ba7133b9f63b03b985a9bfdd27dac5528 | |
parent | 6f3cb059fd1f3a57ffd70c9d54a394a85a6ea13d (diff) | |
download | cpython-d0aac5da59b1bbd113e6081d7c807ad5bced8a05.zip cpython-d0aac5da59b1bbd113e6081d7c807ad5bced8a05.tar.gz cpython-d0aac5da59b1bbd113e6081d7c807ad5bced8a05.tar.bz2 |
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 7eebeb8fb84e2a9cb73903a08c59cf1d3b32cee0)
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 0cddf4a..755ee65 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): |