Skip to content

TST: assert_produces_warning multiple warnings/messages #56555

Closed
@jbrockmendel

Description

@jbrockmendel

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

NA

Issue Description

Sometimes when deprecating something I will find a test like:

def test_foo():
    with tm.assert_produces_warning(UnrelatedWarning, match=unrelated_msg):
        thing_that_i_am_deprecating()

When this happens, the only viable option I'm aware of is to change UnrelatedWarning to (UnrelatedWarning, FutureWarning). But this doesn't a) check that we get both or b) check that we get a reasonable message for the FutureWarning.

The request here is for a way to specify a list of (warning, msg) pairs and check that we get all of them and no others. Or to make @pytest.mark.filterwarnings("ignore:my_message:FutureWarning") actually work in this context.

Expected Behavior

NA

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions