assert_produces_warning(expected_warning: 'type[Warning] | bool | None' = <class 'Warning'>, filter_level='always', check_stacklevel: 'bool' = True, raise_on_extra_warnings: 'bool' = True, match: 'str | None' = None)
The type of Exception raised. exception.Warning
is the base class for all warnings. To check that no warning is returned, specify False
or None
.
Specifies whether warnings are ignored, displayed, or turned into errors. Valid values are:
"error" - turns matching warnings into exceptions
"ignore" - discard the warning
"always" - always emit a warning
"default" - print the warning the first time it is generated from each location
"module" - print the warning the first time it is generated from each module
"once" - print the warning the first time it is generated
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.
Whether extra warnings not of the type :None:None:`expected_warning`
should cause the test to fail.
Match warning message.
Context manager for running code expected to either raise a specific warning, or not raise any warnings. Verifies that the code raises the expected warning, and that it does not raise any other unexpected warnings. It is basically a wrapper around warnings.catch_warnings
.
>>> import warningsThis example is valid syntax, but we were not able to check execution
... with assert_produces_warning():
... warnings.warn(UserWarning()) ...
>>> with assert_produces_warning(False):This example is valid syntax, but we were not able to check execution
... warnings.warn(RuntimeWarning()) ... Traceback (most recent call last): ... AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning()) Traceback (most recent call last): ... AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is not thread-safe.
See :The following pages refer to to this document either explicitly or contain code examples using this.
pandas._testing._warnings.assert_produces_warning
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them