Skip to content

TEST: Simplify warning checks #810

Open
@effigies

Description

@effigies

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions