[issue3781] warnings.catch_warnings fails gracelessly when recording warnings but no warnings are emitted

Jean-Paul Calderone report at bugs.python.org
Fri Sep 5 00:10:09 CEST 2008


New submission from Jean-Paul Calderone <exarkun at divmod.com>:

This example shows the behavior:

    from warnings import catch_warnings

    def test():
        with catch_warnings(True) as w:
            assert str(w.message) == "foo", "%r != %r" % (w.message, "foo")

    test()

This fails with an IndexError from the `w.message`.  That's a bit
surprising, and since this is mostly an API useful for testing, it'd be
much better if it had a well-defined, documented (ie, stable and likely
to continue working in the next release of Python) error mode.

----------
components: Library (Lib)
messages: 72533
nosy: exarkun
severity: normal
status: open
title: warnings.catch_warnings fails gracelessly when recording warnings but no warnings are emitted
type: behavior
versions: Python 2.6

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


More information about the Python-bugs-list mailing list