diff options
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() |