Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
rhshadrach committed Apr 13, 2024
commit d13e876b6dc33c70b452e76e5a6f7db9e5113bc6
39 changes: 38 additions & 1 deletion pandas/tests/util/test_assert_produces_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def f():
warnings.warn("f2", RuntimeWarning)


@pytest.mark.filterwarnings("ignore:f1:FutureWarning")
def test_assert_produces_warning_honors_filter():
# Raise by default.
msg = r"Caused unexpected warning\(s\)"
Expand Down Expand Up @@ -179,6 +178,44 @@ def test_match_multiple_warnings():
warnings.warn("Match this too", UserWarning)


def test_must_match_multiple_warnings():
# https://github.com/pandas-dev/pandas/issues/56555
category = (FutureWarning, UserWarning)
msg = "Did not see expected warning of class 'UserWarning'"
with pytest.raises(AssertionError, match=msg):
with tm.assert_produces_warning(category, match=r"^Match this"):
warnings.warn("Match this", FutureWarning)


def test_must_match_multiple_warnings_messages():
# https://github.com/pandas-dev/pandas/issues/56555
category = (FutureWarning, UserWarning)
msg = r"The emitted warning messages are \[UserWarning\('Not this'\)\]"
with pytest.raises(AssertionError, match=msg):
with tm.assert_produces_warning(category, match=r"^Match this"):
warnings.warn("Match this", FutureWarning)
warnings.warn("Not this", UserWarning)


def test_allow_partial_match_for_multiple_warnings():
# https://github.com/pandas-dev/pandas/issues/56555
category = (FutureWarning, UserWarning)
with tm.assert_produces_warning(
category, match=r"^Match this", must_find_all_warnings=False
):
warnings.warn("Match this", FutureWarning)


def test_allow_partial_match_for_multiple_warnings_messages():
# https://github.com/pandas-dev/pandas/issues/56555
category = (FutureWarning, UserWarning)
with tm.assert_produces_warning(
category, match=r"^Match this", must_find_all_warnings=False
):
warnings.warn("Match this", FutureWarning)
warnings.warn("Not this", UserWarning)


def test_right_category_wrong_match_raises(pair_different_warnings):
target_category, other_category = pair_different_warnings
with pytest.raises(AssertionError, match="Did not see warning.*matching"):
Expand Down