summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/test_umath.py7
-rw-r--r--numpy/testing/utils.py7
2 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 7bcec3114..56e7311e2 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -678,10 +678,9 @@ class TestMinMax(TestCase):
for i in range(inp.size):
inp[:] = np.arange(inp.size, dtype=dt)
inp[i] = np.nan
- self.assertTrue(np.isnan(inp.max()),
- msg=repr(inp) + '\n' + msg)
- self.assertTrue(np.isnan(inp.min()),
- msg=repr(inp) + '\n' + msg)
+ emsg = lambda: '%r\n%s' % (inp, msg)
+ assert_(np.isnan(inp.max()), msg=emsg)
+ assert_(np.isnan(inp.min()), msg=emsg)
inp[i] = 1e10
assert_equal(inp.max(), 1e10, err_msg=msg)
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