summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-06-01 08:47:13 -0500
committerGitHub <noreply@github.com>2020-06-01 08:47:13 -0500
commitc25557e0a9b2d80950a8501062fc337913a3549f (patch)
treef0511de90b9c10d7756848db583c090e29e34b8e /numpy/testing/_private/utils.py
parentbdd4e2e29c4b011cf455a72f85c92010656d2722 (diff)
parentff5680a0298251d8df7958f47032ac02cdea80e3 (diff)
downloadnumpy-c25557e0a9b2d80950a8501062fc337913a3549f.tar.gz
Merge pull request #16463 from sethtroisi/tst_filter_filtered
DOC: Improve assert_warns docstring with example
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index f8789af90..ef623255b 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -1768,15 +1768,28 @@ def assert_warns(warning_class, *args, **kwargs):
----------
warning_class : class
The class defining the warning that `func` is expected to throw.
- \\*args : List of function and arguments
- `func` and arguments for `func`.
- \\*\\*kwargs : Kwargs
+ func : callable, optional
+ Callable to test
+ *args : Arguments
+ Arguments for `func`.
+ **kwargs : Kwargs
Keyword 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
+ >>> # or passing a func
+ >>> ret = np.testing.assert_warns(DeprecationWarning, deprecated_func, 4)
+ >>> assert ret == 16
"""
if not args:
return _assert_warns_context(warning_class)