@@ -2339,12 +2339,42 @@ def exception_matches(self, exc_type, exc_value, trace_back):
2339
2339
def assert_produces_warning (expected_warning = Warning , filter_level = "always" ,
2340
2340
clear = None , check_stacklevel = True ):
2341
2341
"""
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``.
2347
2346
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
+ ----------
2348
2378
>>> import warnings
2349
2379
>>> with assert_produces_warning():
2350
2380
... warnings.warn(UserWarning())
0 commit comments