Count warnings in Python 2.4

Posted by l0b0 on Stack Overflow See other posts from Stack Overflow or by l0b0
Published on 2010-02-24T09:17:01Z Indexed on 2010/03/25 9:53 UTC
Read the original article Hit count: 437

Filed under:
|

I've got some tests that need to count the number of warnings raised by a function. In Python 2.6 this is simple, using

with warnings.catch_warnings(record=True) as warn:
    ...
    self.assertEquals(len(warn), 2)

Unfortunately, with is not available in Python 2.4, so what else could I use? I can't simply check if there's been a single warning (using warning filter with action='error' and try/catch), because the number of warnings is significant.

© Stack Overflow or respective owner

Related posts about python-2.4

Related posts about warnings