8000 TST: assert_produces_warning works with filterwarnings by TomAugspurger · Pull Request #25721 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

TST: assert_produces_warning works with filterwarnings #25721

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

Merged
merged 5 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

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
remove message
  • Loading branch information
TomAugspurger committed Mar 14, 2019
commit ff66c6b9aa6218b59bf74a1eab56f1b9c41582e0
6 changes: 0 additions & 6 deletions pandas/tests/util/test_assert_produces_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ def f(a=FutureWarning, b=RuntimeWarning):
def test_assert_produces_warning_honors_filter():
with tm.assert_produces_warning(RuntimeWarning):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be testing the new option here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... I've messed something up, sorry.

f()


@pytest.mark.filterwarnings('ignore:f1:FutureWarning')
def test_assert_produces_warning_message():
with tm.assert_produces_warning(FutureWarning, message='f2'):
f(FutureWarning, FutureWarning)
9 changes: 3 additions & 6 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,8 +2571,7 @@ def exception_matches(self, exc_type, exc_value, trace_back):

@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True,
message=''):
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
Expand Down Expand Up @@ -2610,9 +2609,6 @@ class for all warnings. To check that no warning is returned,
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
message : str, default ''
Use in the filter with `filter_level` and `expected_warning`
the control which warnings the filter applies to.

Examples
--------
Expand Down Expand Up @@ -2652,7 +2648,8 @@ class for all warnings. To check that no warning is returned,

saw_warning = False
if expected_warning and filter_level:
warnings.filterwarnings(filter_level, message, expected_warning)
warnings.filterwarnings(filter_level, message='',
category=expected_warning)
elif filter_level:
# no expected warnings.
warnings.simplefilter(filter_level)
Expand Down
0