I'm learning on writing custom opkernel with TF2.0, and use DCHECK_EQ to ensure the dim size of my input. When I begin to write the test_case using the tf.test, I found it behaves different with how TF1 treats with the DCHECK.
def test_raisesExceptionWithIncompatibleDimensions(self):
with tf.Session(''):
with self.assertRaises(ValueError):
inner_product_module.inner_product([1, 2], [[1, 2], [3, 4]]).eval()
with self.assertRaises(ValueError):
self.assertRaises(inner_product_module.inner_product([1, 2], [1, 2, 3, 4]).eval(), ValueError)
with self.assertRaises(ValueError):
self.assertRaises(inner_product_module.inner_product([1, 2, 3], [[1, 2], [3, 4]]).eval(), ValueError)
But in TF2, though I change the tf.Session("") into self.session(), the DCHECK_EQ exception in my custom op can not be caught by this assertRaises, and it just exits mu test program with signal 6 and logs the stack trace.
How to assert the DCHECK_XX in TF2? Hope someone can offer an example.
Many thanks