summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_warnings/__init__.py')
-rw-r--r--Lib/test/test_warnings/__init__.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index 2c54e61..86c2f22 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -877,6 +877,25 @@ class WarningsDisplayTests(BaseTest):
file_object, expected_file_line)
self.assertEqual(expect, file_object.getvalue())
+ def test_formatwarning_override(self):
+ # bpo-35178: Test that a custom formatwarning function gets the 'line'
+ # argument as a positional argument, and not only as a keyword argument
+ def myformatwarning(message, category, filename, lineno, text):
+ return f'm={message}:c={category}:f={filename}:l={lineno}:t={text}'
+
+ file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
+ line_num = 3
+ file_line = linecache.getline(file_name, line_num).strip()
+ message = 'msg'
+ category = Warning
+ file_object = StringIO()
+ expected = f'm={message}:c={category}:f={file_name}:l={line_num}' + \
+ f':t={file_line}'
+ with support.swap_attr(self.module, 'formatwarning', myformatwarning):
+ self.module.showwarning(message, category, file_name, line_num,
+ file_object, file_line)
+ self.assertEqual(file_object.getvalue(), expected)
+
class CWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
module = c_warnings