-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bug: assert_produces_warning(None) not raising AssertionError with warning #38626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
724a2af
0a625f3
2e1d58a
aed3465
c82b859
1938ad9
6f3c8ff
8193ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2724,11 +2724,10 @@ class for all warnings. To check that no warning is returned, | |
extra_warnings = [] | ||
|
||
for actual_warning in w: | ||
if not expected_warning: | ||
continue | ||
|
||
expected_warning = cast(Type[Warning], expected_warning) | ||
if issubclass(actual_warning.category, expected_warning): | ||
if expected_warning and issubclass( | ||
actual_warning.category, expected_warning | ||
): | ||
Comment on lines
-2727
to
+2730
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is a good catch. |
||
saw_warning = True | ||
|
||
if check_stacklevel and issubclass( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,6 +543,7 @@ def test_tda_add_sub_index(self): | |
expected = tdi - tdi | ||
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.xfail(reason="GH38630", strict=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason you are passing strict? we default to true - eg if these are fixed we want the tests to fail (as a hint to remove the xfail) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem I ran into is that some parameterizations actually pass, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok that's fine ping on green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing 2 failures where Do you know if this warning occurs consistently? Should something in the test be modified to handle a potential There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we ar trying to track these cases down as something is leaking if they r causing actual failures then ok to xfail (and list these in the associated issue with checkboxes) |
||
def test_tda_add_dt64_object_array(self, box_with_array, tz_naive_fixture): | ||
# Result should be cast back to DatetimeArray | ||
box = box_with_array | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,3 +152,20 @@ def test_right_category_wrong_match_raises(pair_different_warnings): | |
with tm.assert_produces_warning(target_category, match=r"^Match this"): | ||
warnings.warn("Do not match it", target_category) | ||
warnings.warn("Match this", other_category) | ||
|
||
|
||
@pytest.mark.parametrize("false_or_none", [False, None]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good tests to prevent the issue from happening! |
||
class TestFalseOrNoneExpectedWarning: | ||
def test_raise_on_warning(self, false_or_none): | ||
msg = r"Caused unexpected warning\(s\)" | ||
with pytest.raises(AssertionError, match=msg): | ||
with tm.assert_produces_warning(false_or_none): | ||
f() | ||
|
||
def test_no_raise_without_warning(self, false_or_none): | ||
with tm.assert_produces_warning(false_or_none): | ||
pass | ||
|
||
def test_no_raise_with_false_raise_on_extra(self, false_or_none): | ||
with tm.assert_produces_warning(false_or_none, raise_on_extra_warnings=False): | ||
f() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this code functionally the same as existing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought if
expected_warning
isFalse
orNone
, thenextra_warnings
does not get appended to because of thecontinue
. So the check at the end for raising on extra warnings doesn't get triggered.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation will ignore the else clause below, which consolidates extra warnings. I see that I messed that up in one of my previous PRs. This PR reverts that error.
Probably, if some functions are extracted, that would improve the readability of the logic (maybe in a separate PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added tests do raise on master as well, so behavior for them has changed