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: Enable warnings by default in unittest
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: brett.cannon, brian.curtin, davide.rizzo, eric.araujo, ezio.melotti, michael.foord
Priority: normal Keywords: patch

Created on 2010年11月25日 22:08 by ezio.melotti, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10535.diff ezio.melotti, 2010年11月26日 05:18 working patch (without docs and tests) review
issue10535-2.diff ezio.melotti, 2010年11月29日 09:38 patch w/ docs and tests
warnings.diff brian.curtin, 2010年12月02日 19:37 review
Messages (13)
msg122411 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年11月25日 22:08
Warnings should be on by default in unittest so that developers can see them while running the tests even if they are silenced by default in Python.
The plan is to add a "warnings" argument to TestProgram and the default TextTestRunner:
 * if the argument is passed always use it as a filter (e.g. default, ignore, all, ...) for warnings;
 * if the argument is not passed and sys.warnoptions is not [] (i.e. python has been called with "-W something") don't do anything (i.e. use the warnings specified by -W);
 * if the argument is not passed and sys.warnoptions is [], use 'default' (i.e. show warnings).
In order to prevent floods of warnings when the deprecated assertEquals, assert_, etc. are used (see #9424), a new type of warning could be created (e.g. _UnittestDeprecationWarning) and filtered so that these warnings are printed only once.
msg122438 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年11月26日 05:18
Here's a working patch (without docs and tests).
I managed to filter the warnings by message without introducing a new type of warning. As it is, all the warnings related to deprecated unittest methods are printed only once per module, regardless of what methods are used and how many times.
I'm also thinking that it might be better to include the name of the deprecated method in the message and use three filters for fail* methods, assert* methods, and the assert*Regexp* methods that will be deprecated. This will show at worst 3 warnings per module, but the assert*Regexp* and the fail* methods are not so common, so it shouldn't be too nosy.
One "limitation" of the patch is that the per-module special-casing for unittest is not affect by the `warnings` argument, but it can be changed when -W is used and no `warnings` arg is passed.
Regrtest doesn't seem to use unittest, so it should be fixed separately (probably needs another issue).
msg122470 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010年11月26日 18:35
"I'm also thinking that it might be better to include the name of the deprecated method in the message and use three filters for fail* methods, assert* methods, and the assert*Regexp* methods that will be deprecated."
That sounds good, well - it sounds *essential*.
msg122779 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年11月29日 08:41
Attached a new patch.
A few comments about it:
1) A new category for UnittestWarnings could still be added to make it easier to filter warnings using the -W python flags and thus providing more control;
2) I didn't change the deprecation message in the patch -- I will probably do it in a separate commit;
3) The patch touches a few unrelated unittest/test/test_*.py files that were checking for the number of args explicitely;
4) In order to test the different combinations of flags/args I created a new _test_warnings.py file called from test_runner.py via subprocess;
5) unittest warnings are now printed only once even when 'always' is passed as an arg, but not when it's set with -W (this somehow addresses the "limitation" described in my previous message);
msg122966 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010年12月01日 00:58
Committed in r86908. I'll leave this open because there still a few things (proposed in the previous message) that can be changed/improved.
msg123104 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010年12月02日 19:37
Here's a patch for the ResourceWarnings that were introduced.
msg131221 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011年03月17日 04:57
Does Brian's patch still need applying? (Can this be closed?)
msg131222 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011年03月17日 05:14
Brian's patch is not yet applied afaik, but I couldn't see the warnings here, so it might be something specific to Windows. Brian, can you confirm if you still see the problem?
Changing the warning type (to UnittestWarning) and the error message can still be done if you think it's a good idea.
Since this fix didn't affect regrtest, another issue for it might be necessary too.
msg131251 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011年03月17日 14:04
I'm not seeing those warnings anymore, so I think the patch can be ignored.
msg180099 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013年01月16日 18:47
Ezio, do you want to create separate issues for any of the TODOs you wanted in http://bugs.python.org/issue10535#msg122779 so we can close this bug?
msg180244 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013年01月19日 12:54
The two TODOs left are:
 1) adding UnittestWarning;
 2) improving the error message for deprecations;
Technically these are new features, so they can go in 3.4 only, but 2) might be simple enough to be backported.
Regarding 1) it might be a bit too late, given that most deprecations have been around for 2-3 versions already.
msg180254 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013年01月19日 19:21
I wouldn't backport; not worth it.
Anyway, since I consider this bug closed I'm taking myself off the nosy list.
msg180272 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013年01月19日 22:47
Agreed, closing.
History
Date User Action Args
2022年04月11日 14:57:09adminsetgithub: 54744
2013年01月19日 22:48:00ezio.melottisetstatus: open -> closed
versions: + Python 3.2, - Python 3.4
messages: + msg180272

resolution: fixed
stage: patch review ->
2013年01月19日 19:21:43brett.cannonsetnosy: brett.cannon, ezio.melotti, eric.araujo, michael.foord, brian.curtin, davide.rizzo
messages: + msg180254
2013年01月19日 12:54:24ezio.melottisetstatus: pending -> open

messages: + msg180244
2013年01月16日 20:17:46brett.cannonsetstatus: open -> pending
2013年01月16日 18:47:59brett.cannonsetstatus: pending -> open
versions: + Python 3.4, - Python 3.2
2013年01月16日 18:47:54brett.cannonsetstatus: open -> pending

messages: + msg180099
2011年03月17日 14:04:13brian.curtinsetnosy: brett.cannon, ezio.melotti, eric.araujo, michael.foord, brian.curtin, davide.rizzo
messages: + msg131251
2011年03月17日 05:14:53ezio.melottisetnosy: brett.cannon, ezio.melotti, eric.araujo, michael.foord, brian.curtin, davide.rizzo
messages: + msg131222
2011年03月17日 04:57:10michael.foordsetnosy: brett.cannon, ezio.melotti, eric.araujo, michael.foord, brian.curtin, davide.rizzo
messages: + msg131221
2010年12月02日 19:37:59brian.curtinsetfiles: + warnings.diff
nosy: + brian.curtin
messages: + msg123104

2010年12月01日 00:58:37ezio.melottisetmessages: + msg122966
2010年11月29日 09:38:35ezio.melottisetfiles: + issue10535-2.diff
2010年11月29日 09:38:17ezio.melottisetfiles: - issue10535-2.diff
2010年11月29日 08:41:34ezio.melottisetfiles: + issue10535-2.diff

messages: + msg122779
2010年11月26日 18:35:48michael.foordsetmessages: + msg122470
2010年11月26日 13:17:41davide.rizzosetnosy: + davide.rizzo
2010年11月26日 05:18:26ezio.melottisetfiles: + issue10535.diff
keywords: + patch
messages: + msg122438

stage: needs patch -> patch review
2010年11月26日 04:49:41eric.araujosetnosy: + eric.araujo

components: + Library (Lib)
versions: + Python 3.2
2010年11月25日 22:08:33ezio.melotticreate

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