Skip to content

Commit 0519914

Browse files
authored
Bug: assert_produces_warning(None) not raising AssertionError with warning (#38626)
1 parent ca52e39 commit 0519914

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

pandas/_testing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2724,11 +2724,10 @@ class for all warnings. To check that no warning is returned,
27242724
extra_warnings = []
27252725

27262726
for actual_warning in w:
2727-
if not expected_warning:
2728-
continue
2729-
27302727
expected_warning = cast(Type[Warning], expected_warning)
2731-
if issubclass(actual_warning.category, expected_warning):
2728+
if expected_warning and issubclass(
2729+
actual_warning.category, expected_warning
2730+
):
27322731
saw_warning = True
27332732

27342733
if check_stacklevel and issubclass(

pandas/tests/arithmetic/test_timedelta64.py

+1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ def test_tda_add_sub_index(self):
543543
expected = tdi - tdi
544544
tm.assert_index_equal(result, expected)
545545

546+
@pytest.mark.xfail(reason="GH38630", strict=False)
546547
def test_tda_add_dt64_object_array(self, box_with_array, tz_naive_fixture):
547548
# Result should be cast back to DatetimeArray
548549
box = box_with_array

pandas/tests/frame/test_arithmetic.py

+1
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ def test_frame_with_frame_reindex(self):
821821
(np.datetime64(20, "ns"), "<M8[ns]"),
822822
],
823823
)
824+
@pytest.mark.xfail(reason="GH38630", strict=False)
824825
@pytest.mark.parametrize(
825826
"op",
826827
[

pandas/tests/indexes/test_common.py

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def test_ravel_deprecation(self, index):
357357
with tm.assert_produces_warning(FutureWarning):
358358
index.ravel()
359359

360+
@pytest.mark.xfail(reason="GH38630", strict=False)
360361
def test_asi8_deprecation(self, index):
361362
# GH#37877
362363
if isinstance(

pandas/tests/io/parser/test_common.py

+1
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ def test_parse_integers_above_fp_precision(all_parsers):
11361136
tm.assert_frame_equal(result, expected)
11371137

11381138

1139+
@pytest.mark.xfail(reason="GH38630, sometimes gives ResourceWarning", strict=False)
11391140
def test_chunks_have_consistent_numerical_type(all_parsers):
11401141
parser = all_parsers
11411142
integers = [str(i) for i in range(499999)]

pandas/tests/util/test_assert_produces_warning.py

+17
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,20 @@ def test_right_category_wrong_match_raises(pair_different_warnings):
152152
with tm.assert_produces_warning(target_category, match=r"^Match this"):
153153
warnings.warn("Do not match it", target_category)
154154
warnings.warn("Match this", other_category)
155+
156+
157+
@pytest.mark.parametrize("false_or_none", [False, None])
158+
class TestFalseOrNoneExpectedWarning:
159+
def test_raise_on_warning(self, false_or_none):
160+
msg = r"Caused unexpected warning\(s\)"
161+
with pytest.raises(AssertionError, match=msg):
162+
with tm.assert_produces_warning(false_or_none):
163+
f()
164+
165+
def test_no_raise_without_warning(self, false_or_none):
166+
with tm.assert_produces_warning(false_or_none):
167+
pass
168+
169+
def test_no_raise_with_false_raise_on_extra(self, false_or_none):
170+
with tm.assert_produces_warning(false_or_none, raise_on_extra_warnings=False):
171+
f()

0 commit comments

Comments
 (0)