[New-bugs-announce] [issue15626] unittest.main negates -bb option and programmatic warning configuration

Ben Darnell report at bugs.python.org
Sun Aug 12 02:12:56 CEST 2012


New submission from Ben Darnell:

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.

----------
files: testbb.py
messages: 168013
nosy: Ben.Darnell
priority: normal
severity: normal
status: open
title: unittest.main negates -bb option and programmatic warning configuration
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file26771/testbb.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15626>
_______________________________________


More information about the New-bugs-announce mailing list