summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-18 23:47:17 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-18 23:47:17 (GMT)
commit1231a4615fd447f0988a72a134a1fc5e7d4e8d69 (patch)
tree1c4a7618f38dfac14417cb3546a7095def5054aa /Lib/test/test_warnings
parent81ae89b6114f866870c42e42263bee8ce2ef5395 (diff)
downloadcpython-1231a4615fd447f0988a72a134a1fc5e7d4e8d69.zip
cpython-1231a4615fd447f0988a72a134a1fc5e7d4e8d69.tar.gz
cpython-1231a4615fd447f0988a72a134a1fc5e7d4e8d69.tar.bz2
Add _showwarnmsg() and _formatwarnmsg() to warnings
Issue #26568: add new _showwarnmsg() and _formatwarnmsg() functions to the warnings module. The C function warn_explicit() now calls warnings._showwarnmsg() with a warnings.WarningMessage as parameter, instead of calling warnings.showwarning() with multiple parameters. _showwarnmsg() calls warnings.showwarning() if warnings.showwarning() was replaced. Same for _formatwarnmsg(): call warnings.formatwarning() if it was replaced.
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index cea9c57..70eae4c 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -651,6 +651,17 @@ class _WarningsTests(BaseTest, unittest.TestCase):
result = stream.getvalue()
self.assertIn(text, result)
+ def test_showwarnmsg_missing(self):
+ # Test that _showwarnmsg() missing is okay.
+ 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()
+ self.assertIn(text, result)
+
def test_showwarning_not_callable(self):
with original_warnings.catch_warnings(module=self.module):
self.module.filterwarnings("always", category=UserWarning)