catch_warnings

class astropy.tests.helper.catch_warnings(*classes)[source] [edit on github]

Bases: warnings.catch_warnings

A high-powered version of warnings.catch_warnings to use for testing and to make sure that there is no dependence on the order in which the tests are run.

This completely blitzes any memory of any warnings that have appeared before so that all warnings will be caught and displayed.

*args is a set of warning classes to collect. If no arguments are provided, all warnings are collected.

Use as follows:

with catch_warnings(MyCustomWarning) as w:
    do.something.bad()
assert len(w) > 0