homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve "test_support.check_warnings()"
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: flox Nosy List: benjamin.peterson, brett.cannon, ezio.melotti, flox, mark.dickinson, pitrou
Priority: high Keywords: patch

Created on 2010年02月03日 20:02 by flox, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue7849_lib_fixes.diff flox, 2010年02月03日 20:06 Patch, apply to trunk
issue7849_check_warnings_v3.diff flox, 2010年03月07日 01:05 Patch, apply to 2.x
Messages (12)
msg98796 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年02月03日 20:02
Currently this context manager is used in 3 different situations:
 - to silence standard warnings
 - to record warnings in a list, in order to verify them
 - to silence py3k warnings
But it does not accept any parameter, and it does not *check* if the filter is obsolete. It silence *all* warnings, blindly.
I would like to propose an enhancement of this function, which accepts a list of filters as parameters, and which verifies that there's really something to catch.
An optional boolean argument "lazy" can be used to disable the check.
 check_warnings([filter[, ...[, lazy=False]]])
Additionnally, a sister function will filter only the py3k warnings:
 check_py3k_warnings([filter[, ...[, lazy=False]]])
See the patch and its docstring for details.
Note: this context manager could be used to fix the last part of #7092 
msg98797 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年02月03日 20:06
Patch for the context managers.
Patch to fix the stdlib.
msg98799 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010年02月03日 21:07
In other words you want a way to limit what the context manager catches and records while allowing all other warnings to propagate. That seems fine.
I didn't do much of a code review, but there is a grammatical error in the docstring: change "a filter catch nothing" to "a filter catches nothing".
msg98800 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年02月03日 21:24
Actually this patch enhances check_warnings() in other ways too:
 - it verifies if the warning is effectively raised
 - it deals with "py3k" warnings separately
It could be used instead of warnings.filterwarnings() with some benefits.
msg98802 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年02月03日 23:11
Fixed. Tested with different options: "-Wd", "-3"
msg100242 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010年03月01日 03:34
"lazy" sounds like a bad name for that parameter. It makes me think of lazy evaluation, not error checking.
There's also the problem that check_py3k_warnings() will check all DeprecationWarnings, not only py3k-specific ones. We need a Py3kDeprecationWarning subclass.
Besides, there doesn't seem to be any point accepting positional arguments in check_py3k_warnings(). If you want a custom filter, just use check_warnings() instead.
msg100244 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年03月01日 04:18
+1 on Py3kDeprecationWarning.
msg100251 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年03月01日 09:16
> Antoine Pitrou <pitrou@free.fr> added the comment:
>
> "lazy" sounds like a bad name for that parameter. It makes me think of lazy evaluation, not error checking.
>
"check_warnings(quiet=True)" sounds good?
> There's also the problem that check_py3k_warnings() will check all DeprecationWarnings, not only py3k-specific ones. We need a Py3kDeprecationWarning subclass.
+0 about this additional subclass, because the current py3k warnings
are around since 2.6 (r55525).
And if the subclass is accepted, we will need Py3kSyntaxWarning too.
Maybe the "-3" warnings should become "-Wd" warnings at some point,
because 3.2 will probably become trunk after
"branches/release27-maint/" is created. Then we will deprecate the
"-3" switch :)
> Besides, there doesn't seem to be any point accepting positional arguments in check_py3k_warnings(). If you want a custom filter, just use check_warnings() instead.
>
Both are needed, because the "check_py3k_warnings" is no-op except if
"-3" is passed on the command line.
I thought to implement "check_warnings(py3k=True)", at first. But
since this function will be used in 83% of the cases, it may be more
convenient to use a specific name "check_py3k_warnings":
 - 56 test modules will use check_py3k_warnings
 - 11 test modules will use check_warnings
msg100526 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010年03月06日 11:31
This is somewhat orthogonal, but it might also be nice to have some way to tell check_warnings not to touch __warningregistry__. See also issue 4180.
msg100556 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年03月07日 01:05
Patch updated.
msg101412 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年03月21日 01:28
Done on trunk with r78758 and r79049.
msg112506 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年08月02日 18:14
I backported this to 2.6 in r83537 in order to fix #7092. I used a leading underscore on _check_py3k_warnings to make it private because no new features should be added to 2.6.
History
Date User Action Args
2022年04月11日 14:56:57adminsetgithub: 52097
2010年08月02日 18:14:14ezio.melottisetmessages: + msg112506
2010年03月21日 01:28:19floxsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg101412

stage: commit review -> resolved
2010年03月07日 01:05:51floxsetfiles: + issue7849_check_warnings_v3.diff
versions: + Python 3.2
messages: + msg100556

assignee: flox
resolution: accepted
2010年03月07日 01:04:26floxsetfiles: - issue7849_check_warnings_v2.diff
2010年03月06日 11:31:42mark.dickinsonsetnosy: + mark.dickinson
messages: + msg100526
2010年03月01日 09:16:31floxsetmessages: + msg100251
2010年03月01日 04:18:27ezio.melottisetmessages: + msg100244
2010年03月01日 03:34:36pitrousetnosy: + pitrou, benjamin.peterson
messages: + msg100242
2010年02月27日 17:03:40floxsetstage: commit review
2010年02月03日 23:11:20floxsetfiles: + issue7849_check_warnings_v2.diff

messages: + msg98802
2010年02月03日 23:07:47floxsetfiles: - issue7849_check_warnings.diff
2010年02月03日 21:24:09floxsetmessages: + msg98800
2010年02月03日 21:07:10brett.cannonsetnosy: + brett.cannon
messages: + msg98799
2010年02月03日 20:09:42floxlinkissue7092 dependencies
2010年02月03日 20:07:00floxsetfiles: + issue7849_lib_fixes.diff

messages: + msg98797
2010年02月03日 20:04:07floxsetfiles: + issue7849_check_warnings.diff
keywords: + patch
2010年02月03日 20:02:30floxcreate

AltStyle によって変換されたページ (->オリジナル) /