classification
Title: warnings.filterwarnings doesn't work with -O
Type: Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, eric.araujo, michael.foord, rhettinger
Priority: high Keywords: patch

Created on 2010-06-25 21:00 by michael.foord, last changed 2010-09-27 22:46 by michael.foord. This issue is now closed.

Messages (8)
msg108628 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-06-25 21:00
warnings.filterwarnings is mostly a bunch of asserts, so it doesn't work when Python is run with -O or -OO. This also means that a bunch of tests fail when run with -O or -OO.

Two options are skip the tests or fix filterwarnings.
msg108629 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-06-25 21:01
A third (and better) option, but a deeper change, would be to allow the enabling of asserts on a per-module basis even when Python is run with -O/-OO. This would be great for testing.
msg117474 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-09-27 21:23
What specific failures are you talking about, Michael? I just ran regrtest with -O and had no (unexpected) failures.
msg117475 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-27 21:38
When I run with -OO I get 42 test failures. Most of them look like they are due to missing docstrings but some are likely to be due to missing asserts.

42 tests failed:
    test_bisect test_cmd test_code test_collections test_compileall
    test_ctypes test_decimal test_deque test_descrtut test_dictcomps
    test_difflib test_dis test_distutils test_doctest test_extcall
    test_generators test_genexps test_getopt test_http_cookies
    test_import test_itertools test_json test_lib2to3 test_listcomps
    test_math test_metaclass test_pdb test_pickle test_pickletools
    test_pyclbr test_setcomps test_syntax test_threading_local
    test_tokenize test_unpack test_unpack_ex test_urllib2 test_weakref
    test_xml_etree test_xml_etree_c test_zipimport
    test_zipimport_support
msg117482 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-27 22:23
Most of those failures look like they have a similar cause (not all of them though) related to running doctests. When issue 6292 was closed all tests passed with -OO, so this is a regression. I'm raising a separate issue for that. 

Looking at the code actually in warnings.filterwarnings (currently at any rate) I wonder what tests possibly could fail due to the asserts not being run? Maybe I hallucinated the problem... (Or more likely it was actually another issue.)
msg117486 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-09-27 22:28
I'm going to close this as I don't think any of the failures are because of the asserts, else -O would pick them up just as well as -OO.
msg117487 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-27 22:44
Cool - although I *do* see failures under -O; test_import for example. That one is a __pycache__ test, so barry's fault I think.

I'll detail the failures in issue 9964 as I think *most* of them are caused by a problem with pdb.py

In fact, if you run Python with -OO you can't even *import* pdb.

The attached patch fixes that problem (a hasty and untested patch though), and that reduces the number of failures to 5:

5 tests failed:
    test_compileall test_dis test_import test_lib2to3 test_xml_etree
msg117488 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-27 22:46
Oops. The patch should go to issue 9964. Sorry for all this noise.
History
Date User Action Args
2010-09-27 22:46:11michael.foordsetmessages: + msg117488
2010-09-27 22:45:19michael.foordsetfiles: - pdb.diff
2010-09-27 22:44:39michael.foordsetfiles: + pdb.diff
keywords: + patch
messages: + msg117487
2010-09-27 22:28:12brett.cannonsetstatus: open -> closed
resolution: not a bug
messages: + msg117486
2010-09-27 22:23:07michael.foordsetmessages: + msg117482
2010-09-27 21:40:52eric.araujosetnosy: + eric.araujo

versions: - Python 2.6
2010-09-27 21:38:33michael.foordsetmessages: + msg117475
2010-09-27 21:23:42brett.cannonsetmessages: + msg117474
2010-06-25 23:24:28pitrousetpriority: normal -> high
assignee: brett.cannon

nosy: + brett.cannon
versions: + Python 2.6, Python 3.1
2010-06-25 21:06:58michael.foordsetnosy: + rhettinger
2010-06-25 21:01:30michael.foordsetmessages: + msg108629
2010-06-25 21:00:10michael.foordcreate