I have several tests in which I need to count the number of warnings caused by a function. In Python 2.6, it's simple using
with warnings.catch_warnings(record=True) as warn:
...
self.assertEquals(len(warn), 2)
Unfortunately withnot available in Python 2.4, so what else could I use? I can't just check if there was one warning (using warning filter with action='error'and try/ catch), since the number of warnings is significant.
source
share