Re: [docs] Document that filterwarnings(message=...) matches the start of a message (issue 27528)
Reviewers: berkerpeksag, https://bugs.python.org/review/27528/diff/17886/Doc/library/warnings.rst File Doc/library/warnings.rst (right): https://bugs.python.org/review/27528/diff/17886/Doc/library/warnings.rst#new... Doc/library/warnings.rst:145: the warning message must match. (The expression is compiled to always be On 2016/07/16 19:52:04, berkerpeksag wrote:
Can we drop parentheses?
Sure, will do this in next patch version https://bugs.python.org/review/27528/diff/17886/Lib/test/test_warnings/__ini... File Lib/test/test_warnings/__init__.py (right): https://bugs.python.org/review/27528/diff/17886/Lib/test/test_warnings/__ini... Lib/test/test_warnings/__init__.py:274: self.assertListEqual(w, []) On 2016/07/16 19:52:04, berkerpeksag wrote:
assertEqual calls assertListEqual implicitly so I guess this can be replaced with an assertEqual.
Yeah plain assertEqual() should be fine Please review this at https://bugs.python.org/review/27528/ Affected files: Doc/library/warnings.rst Lib/test/test_warnings/__init__.py # HG changeset patch # Parent 0d8f139a6e19f72e3575ee37d410dfe12184be56 Document and test that the beginning of the warning message is matched diff -r 0d8f139a6e19 Doc/library/warnings.rst --- a/Doc/library/warnings.rst Sat Jul 16 07:17:46 2016 +0000 +++ b/Doc/library/warnings.rst Sat Jul 16 07:41:31 2016 +0000 @@ -141,14 +141,15 @@ | | warnings, regardless of location | +---------------+----------------------------------------------+ -* *message* is a string containing a regular expression that the warning message - must match (the match is compiled to always be case-insensitive). +* *message* is a string containing a regular expression that the start of + the warning message must match. (The expression is compiled to always be + case-insensitive.) * *category* is a class (a subclass of :exc:`Warning`) of which the warning category must be a subclass in order to match. * *module* is a string containing a regular expression that the module name must - match (the match is compiled to be case-sensitive). + match. (The expression is compiled to be case-sensitive.) * *lineno* is an integer that the line number where the warning occurred must match, or ``0`` to match all line numbers. diff -r 0d8f139a6e19 Lib/test/test_warnings/__init__.py --- a/Lib/test/test_warnings/__init__.py Sat Jul 16 07:17:46 2016 +0000 +++ b/Lib/test/test_warnings/__init__.py Sat Jul 16 07:41:31 2016 +0000 @@ -263,6 +263,18 @@ self.assertEqual(str(w[-1].message), text) self.assertTrue(w[-1].category is UserWarning) + def test_message_matching(self): + with original_warnings.catch_warnings(record=True, + module=self.module) as w: + self.module.simplefilter("ignore", UserWarning) + self.module.filterwarnings("error", "match", UserWarning) + self.assertRaises(UserWarning, self.module.warn, "match") + self.assertRaises(UserWarning, self.module.warn, "match prefix") + self.module.warn("suffix match") + self.assertListEqual(w, []) + self.module.warn("something completely different") + self.assertListEqual(w, []) + def test_mutate_filter_list(self): class X: def match(self, a):
participants (1)
-
vadmium+py@gmail.com