Make TypeError more explicit on _assertAllCloseRecursive
authorA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 7 Feb 2018 17:08:51 +0000 (09:08 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 7 Feb 2018 17:12:35 +0000 (09:12 -0800)
PiperOrigin-RevId: 184846656

tensorflow/python/framework/test_util.py

index 3864a4aa9effbf094d3c18322ad2578b0dae244f..bfdd98819e27df3419644b58c114cff2941cdb28 100644 (file)
@@ -1146,13 +1146,19 @@ class TensorFlowTestCase(googletest.TestCase):
           del path[-1]
     # a and b are ndarray like objects
     else:
-      self._assertArrayLikeAllClose(
-          a,
-          b,
-          rtol=rtol,
-          atol=atol,
-          msg="Mismatched value: a%s is different from b%s." % (path_str,
-                                                                path_str))
+      try:
+        self._assertArrayLikeAllClose(
+            a,
+            b,
+            rtol=rtol,
+            atol=atol,
+            msg="Mismatched value: a%s is different from b%s." % (path_str,
+                                                                  path_str))
+      except TypeError as e:
+        msg = "Error: a%s has %s, but b%s has %s" % (
+            path_str, type(a), path_str, type(b))
+        e.args = ((e.args[0] + ' : ' + msg,) + e.args[1:])
+        raise
 
   def assertAllClose(self, a, b, rtol=1e-6, atol=1e-6):
     """Asserts that two structures of numpy arrays, have near values.