summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorEvgeni Burovski <evgeni@burovski.me>2015-11-12 17:20:17 +0000
committerEvgeni Burovski <evgeni@burovski.me>2015-11-12 17:20:17 +0000
commit1392e2417150bdea473e3b29867c685c09b25447 (patch)
tree3e09b123a227efdc2cf2c2d41be057fdc00eedd2 /numpy/testing/utils.py
parent4be9ce7bea3321af3c9896da98c751f03459fa38 (diff)
downloadnumpy-1392e2417150bdea473e3b29867c685c09b25447.tar.gz
DOC: document that assert_raises can be used as a context manager
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index c6d863f94..099b75bdf 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -1102,6 +1102,18 @@ def assert_raises(*args,**kwargs):
deemed to have suffered an error, exactly as for an
unexpected exception.
+ Alternatively, `assert_raises` can be used as a context manager:
+
+ >>> from numpy.testing import assert_raises
+ >>> with assert_raises(ZeroDivisionError):
+ ... 1 / 0
+
+ is equivalent to
+
+ >>> def div(x, y):
+ ... return x / y
+ >>> assert_raises(ZeroDivisionError, div, 1, 0)
+
"""
__tracebackhide__ = True # Hide traceback for py.test
nose = import_nose()