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: Incompatible change to test.test_support.check_warnings behaviour
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: flox Nosy List: eric.smith, flox, ncoghlan
Priority: normal Keywords: easy, patch

Created on 2010-03-16 12:45 by ncoghlan, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue8155_check_warnings_quiet_v2.diff flox, 2010-03-17 18:50 Patch, apply to 2.x
Messages (8)
msg101164 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-03-16 12:45
A bug report for the incompatibility I was trying to explain on the checkins list. The test_support module is the only part of the regression test suite that is officially documented, so we can't go changing behaviour that is visible to third parties at will.

Python 2.6.5rc2 (release26-maint:78987, Mar 16 2010, 19:48:42)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from test.test_support import check_warnings
>>> with check_warnings():
...   pass
...
>>>

Python 2.7a4+ (trunk:78987, Mar 16 2010, 19:48:39)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from test.test_support import check_warnings
>>> with check_warnings():
...   pass
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/ncoghlan/devel/python/Lib/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/home/ncoghlan/devel/python/Lib/test/test_support.py", line 568, in _filterwarnings
    missing[0])
AssertionError: filter ('', Warning) did not catch any warning
>>>

Third party test suites may want to use check_warnings() for both 2.6 and 2.7 and this change makes it unnecessarily difficult for them to do so.

Fixing this should just be a matter of flipping the default value of the new "quiet" parameter to True and updating the tests and documentation accordingly.
msg101222 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-17 12:56
here come the patch.
msg101224 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-03-17 13:57
On a quick read through, the patch looks fine to me.

I actually agree it would be nice if we could keep the "quiet=True" default (since it is a better match for the feature set we want in our own tests), but I see the compatibility issue as a deal breaker for that idea.

It's probably worth adding a comment to that effect at the top of the function implementation to help people coming along later and asking "why did they choose the 'wrong' default value?".
msg101225 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-17 14:05
I hesitate to do it differently:

with check_warnings(('', RuntimeWarning)):
 ==> translate to check_warnings(('', RuntimeWarning), quiet=False)

with check_warnings():
 ==> translate to check_warnings(quiet=True)

If the developer passes some arguments to the function, it means that he expects some warnings, and he should not need to add "quiet=False" each time.
And it preserves backward compatibility for existing code.

I guess that we push same behavior for 3.x.
msg101227 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-03-17 14:15
On a second look, there are a couple of things missing:
- the default value didn't actually get changed!
- we should add an explicit test that the no argument behaviour doesn't raise a warning by default

Since we don't really have an existing test suite for the support code, I'd suggest coopting test_sundry.py for the purpose.

I agree that an exception should be raised if the user passes in an expected warning but no warning at all is encountered.
msg101241 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-17 18:50
Patch updated.
msg101244 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-03-17 21:44
Ah, I didn't notice that there were already tests for this in test_warnings (that's what I get for commenting late at night).

Updated patch looks good.
msg101277 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-18 20:01
Fixed with r79049 and r79050.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52402
2010-03-18 20:01:51floxsetstatus: open -> closed
versions: + Python 3.2
messages: + msg101277

resolution: fixed
stage: patch review -> resolved
2010-03-17 21:44:56ncoghlansetmessages: + msg101244
2010-03-17 18:50:15floxsetfiles: + issue8155_check_warnings_quiet_v2.diff

messages: + msg101241
2010-03-17 18:46:59floxsetfiles: - issue8155_check_warnings_quiet.diff
2010-03-17 14:15:17ncoghlansetmessages: + msg101227
2010-03-17 14:05:57floxsetmessages: + msg101225
2010-03-17 13:57:16ncoghlansetmessages: + msg101224
2010-03-17 12:56:19floxsetfiles: + issue8155_check_warnings_quiet.diff

components: + Tests
versions: + Python 2.7
keywords: + easy, patch
nosy: ncoghlan, eric.smith, flox
messages: + msg101222
stage: test needed -> patch review
2010-03-16 13:31:08eric.smithsetnosy: + eric.smith
2010-03-16 12:45:48ncoghlansettitle: Incompoatible change to test.test_support.check_warnings behaviour -> Incompatible change to test.test_support.check_warnings behaviour
2010-03-16 12:45:37ncoghlancreate