Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3d7474

Browse files
committed
Issue #27528: Merge warning doc and test from 3.5
2 parents 36261d7 + 2219450 commit e3d7474

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

Doc/library/warnings.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,15 @@ the disposition of the match. Each entry is a tuple of the form (*action*,
141141
| | warnings, regardless of location |
142142
+---------------+----------------------------------------------+
143143

144-
* *message* is a string containing a regular expression that the warning message
145-
must match (the match is compiled to always be case-insensitive).
144+
* *message* is a string containing a regular expression that the start of
145+
the warning message must match. The expression is compiled to always be
146+
case-insensitive.
146147

147148
* *category* is a class (a subclass of :exc:`Warning`) of which the warning
148149
category must be a subclass in order to match.
149150

150151
* *module* is a string containing a regular expression that the module name must
151-
match (the match is compiled to be case-sensitive).
152+
match. The expression is compiled to be case-sensitive.
152153

153154
* *lineno* is an integer that the line number where the warning occurred must
154155
match, or ``0`` to match all line numbers.

Lib/test/test_warnings/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ def test_filterwarnings(self):
263263
self.assertEqual(str(w[-1].message), text)
264264
self.assertTrue(w[-1].category is UserWarning)
265265

266+
def test_message_matching(self):
267+
with original_warnings.catch_warnings(record=True,
268+
module=self.module) as w:
269+
self.module.simplefilter("ignore", UserWarning)
270+
self.module.filterwarnings("error", "match", UserWarning)
271+
self.assertRaises(UserWarning, self.module.warn, "match")
272+
self.assertRaises(UserWarning, self.module.warn, "match prefix")
273+
self.module.warn("suffix match")
274+
self.assertEqual(w, [])
275+
self.module.warn("something completely different")
276+
self.assertEqual(w, [])
277+
266278
def test_mutate_filter_list(self):
267279
class X:
268280
def match(self, a):

0 commit comments

Comments
 (0)