diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-11-12 11:19:15 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-11-12 11:19:15 -0700 |
commit | f83d68bdac7bf0843f1601da25ac51f97983b1ef (patch) | |
tree | 3e09b123a227efdc2cf2c2d41be057fdc00eedd2 /numpy/testing/utils.py | |
parent | 4be9ce7bea3321af3c9896da98c751f03459fa38 (diff) | |
parent | 1392e2417150bdea473e3b29867c685c09b25447 (diff) | |
download | numpy-f83d68bdac7bf0843f1601da25ac51f97983b1ef.tar.gz |
Merge pull request #6676 from ev-br/assert_raises
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.py | 12 |
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() |