Skip to content

Commit 2a9462a

Browse files
Add clear and other parameter docs to assert_produces_warning
1 parent 4a8496b commit 2a9462a

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

pandas/util/testing.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,12 +2339,42 @@ def exception_matches(self, exc_type, exc_value, trace_back):
23392339
def assert_produces_warning(expected_warning=Warning, filter_level="always",
23402340
clear=None, check_stacklevel=True):
23412341
"""
2342-
Context manager for running code that expects to raise (or not raise)
2343-
warnings. Checks that code raises the expected warning and only the
2344-
expected warning. Pass ``False`` or ``None`` to check that it does *not*
2345-
raise a warning. Defaults to ``exception.Warning``, baseclass of all
2346-
Warnings. (basically a wrapper around ``warnings.catch_warnings``).
2342+
Context manager for running code expected to either raise a specific
2343+
warning, or not raise any warnings. Verifies that the code raises the
2344+
expected warning, and that it does not raise any other unexpected
2345+
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
23472346
2347+
Parameters
2348+
----------
2349+
expected_warning : class Warning|False|None, default Warning
2350+
The type of Exception raised. ``exception.Warning`` is the base
2351+
class for all warnings. To check that no warning is returned,
2352+
specify ``False`` or ``None``.
2353+
filter_level : str, default "always"
2354+
Specifies whether warnings are ignored, displayed, or turned
2355+
into errors.
2356+
Valid values are:
2357+
"error" - turns matching warnings into exeptions
2358+
"ignore" - discard the warning
2359+
"always" - always emit a warning
2360+
"default" - print the warning the first time it is generated
2361+
from each location
2362+
"module" - print the warning the first time it is generated
2363+
from each module
2364+
"once" - print the warning the first time it is generated
2365+
clear : str, default None
2366+
If not ``None`` then remove any previously raised warnings from
2367+
the ``__warningsregistry__`` to ensure that no warning messages are
2368+
suppressed by this context manager. If ``None`` is specified,
2369+
the ``__warningsregistry__`` keeps track of which warnings have been
2370+
shown, and does not show them again.
2371+
check_stacklevel : bool, default true
2372+
If True, displays the line that called the function containing
2373+
the warning to show were the function is called. Otherwise, the
2374+
line that implements the function is displayed.
2375+
2376+
Examples
2377+
----------
23482378
>>> import warnings
23492379
>>> with assert_produces_warning():
23502380
... warnings.warn(UserWarning())

0 commit comments

Comments
 (0)