Open
Description
For the 3.0+ series, we can change this idiom:
with clear_and_catch_warnings() as w:
warnings.simplefilter('always')
# line that is expected to produce warning
assert_equal(len(w), 1)
assert_true(w[0].category is <warningclass>)
To numpy.testing.assert_warns
:
with assert_warns(<warningclass>):
# line that is expected to produce warning
This is generally more readable, IMO, and less prone to disruption when upstream libraries raise extra warnings. For assertions that a line does not raise a warning, we can keep using the old idiom, or write our own.