# catch_warnings¶

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

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:
assert len(w) > 0


Note

Usage of pytest.warns is preferred.

Specify whether to record warnings and if an alternative module should be used other than sys.modules[‘warnings’].

For compatibility with Python 3.0, please consider all arguments to be keyword-only.