bundles / numpy latest / numpy / testing / _private / utils / assert_warns
function
numpy.testing._private.utils:assert_warns
source: build-install/usr/lib/python3.14/site-packages/numpy/testing/_private/utils.py :1989
Signature
def assert_warns ( warning_class , * args , ** kwargs ) Summary
Fail unless the given callable throws the specified warning.
Extended Summary
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.
Parameters
warning_class: classThe class defining the warning that func is expected to throw.
func: callable, optionalCallable to test
*args: ArgumentsArguments for func.
**kwargs: KwargsKeyword arguments for func.
Returns
: The value returned by `func`.
Examples
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 ret = np.testing.assert_warns(DeprecationWarning, deprecated_func, 4) assert ret == 16
Aliases
-
numpy.testing.assert_warns