numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
assert_warns(warning_class, *args, **kwargs)

A warning of class warning_class should be thrown by the callable when invoked with arguments args and keyword arguments kwargs. If a different type of warning is thrown, it will not be caught.

If called with all arguments other than the warning class omitted, may be used as a context manager:

with assert_warns(SomeWarning):

do_something()

The ability to be used as a context manager is new in NumPy v1.11.0.

versionadded

Parameters

warning_class : class

The class defining the warning that :None:None:`func` is expected to throw.

func : callable, optional

Callable to test

*args : Arguments

Arguments for :None:None:`func`.

**kwargs : Kwargs

Keyword arguments for :None:None:`func`.

Returns

The value returned by `func`.

Fail unless the given callable throws the specified warning.

Examples

This example is valid syntax, but we were not able to check execution
>>> import warnings
... def deprecated_func(num):
...  warnings.warn("Please upgrade", DeprecationWarning)
...  return num*num
... with np.testing.assert_warns(DeprecationWarning):
...  assert deprecated_func(4) == 16
... # or passing a func
... ret = np.testing.assert_warns(DeprecationWarning, deprecated_func, 4)
... assert ret == 16
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage._shared._warnings.all_warnings

Local connectivity graph

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


GitHub : /numpy/testing/_private/utils.py#1752
type: <class 'function'>
Commit: