diff options
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 1aee5c507..2a99fe5cb 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -33,6 +33,7 @@ verbose = 0 def assert_(val, msg='') : """ Assert that works in release mode. + Accepts callable msg to allow deferring evaluation until failure. The Python built-in ``assert`` does not work when executing code in optimized mode (the ``-O`` flag) - no byte-code is generated for it. @@ -41,7 +42,11 @@ def assert_(val, msg='') : """ if not val : - raise AssertionError(msg) + try: + smsg = msg() + except TypeError: + smsg = msg + raise AssertionError(smsg) def gisnan(x): """like isnan, but always raise an error if type not supported instead of |