From 1392e2417150bdea473e3b29867c685c09b25447 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Thu, 12 Nov 2015 17:20:17 +0000 Subject: DOC: document that assert_raises can be used as a context manager --- numpy/testing/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'numpy/testing/utils.py') 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() -- cgit v1.2.1