@@ -2339,12 +2339,44 @@ 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 : {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
+
2358
+ * "error" - turns matching warnings into exeptions
2359
+ * "ignore" - discard the warning
2360
+ * "always" - always emit a warning
2361
+ * "default" - print the warning the first time it is generated
2362
+ from each location
2363
+ * "module" - print the warning the first time it is generated
2364
+ from each module
2365
+ * "once" - print the warning the first time it is generated
2366
+
2367
+ clear : str, default None
2368
+ If not ``None`` then remove any previously raised warnings from
2369
+ the ``__warningsregistry__`` to ensure that no warning messages are
2370
+ suppressed by this context manager. If ``None`` is specified,
2371
+ the ``__warningsregistry__`` keeps track of which warnings have been
2372
+ shown, and does not show them again.
2373
+ check_stacklevel : bool, default True
2374
+ If True, displays the line that called the function containing
2375
+ the warning to show were the function is called. Otherwise, the
2376
+ line that implements the function is displayed.
2377
+
2378
+ Examples
2379
+ --------
2348
2380
>>> import warnings
2349
2381
>>> with assert_produces_warning():
2350
2382
... warnings.warn(UserWarning())
0 commit comments