classification
Title: unittest.main negates -bb option and programmatic warning configuration
Type: behavior Stage:
Components: Versions: Python 3.3, Python 3.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, Ben.Darnell, chris.jerdonek, ezio.melotti, michael.foord
Priority: normal Keywords:

Created on 2012-08-12 00:12 by Ben.Darnell, last changed 2012-09-05 01:06 by Arfrever.

Files
File name Uploaded Description Edit
testbb.py Ben.Darnell, 2012-08-12 00:12
Messages (1)
msg168013 - (view) Author: Ben Darnell (Ben.Darnell) Date: 2012-08-12 00:12
In python 3.2, unittest.main by default modifies the warning configuration if no -W options were given on the command line.  This undoes the effect of -bb, turning BytesWarning back into a warning instead of an error.

If both -bb and -Werror::BytesWarning are given, then unittest does not tamper with the warning configuration and byte operations raise errors as expected (but note that -Werror doesn't work in the current version of virtualenv due to https://github.com/pypa/virtualenv/issues/194 ).  unittest.main should check for the -bb flag in addition to sys.warnoptions.

Additionally, if warning filters were modified programmatically before calling unittest.main, unittest will still modify the configuration and potentially override the user's settings.  This is a rarer case, but I've done it before to avoid the problem with -W in a virtualenv (https://github.com/facebook/tornado/blob/master/tornado/test/runtests.py).  It would be good for there to be some way to tell unittest.main not to touch the warnings at all.  main(warnings=False) currently works, but that's relying on an implementation detail (any non-None, non-truthy value works), so either this should be documented or an official way to do the same thing should be added.

The attached test file demonstrates the problem:  when run with -bb, an warning is logged, but the test passes.
History
Date User Action Args
2012-09-05 01:06:25Arfreversetnosy: + Arfrever
2012-08-12 10:37:56pitrousetnosy: + michael.foord

versions: + Python 3.3
2012-08-12 04:56:07r.david.murraysetnosy: + ezio.melotti
2012-08-12 00:59:54chris.jerdoneksetnosy: + chris.jerdonek
2012-08-12 00:12:55Ben.Darnellcreate