Always print message on test failure

Summary: make assertClose print its failure information even if a message is supplied.

Reviewed By: nikhilaravi

Differential Revision: D28799745

fbshipit-source-id: 787c8c356342420cd8f40fdc0b2aba036142298e
This commit is contained in:
Jeremy Reizenstein
2021-06-03 18:29:42 -07:00
committed by Facebook GitHub Bot
parent 7fd7de4451
commit 070ec550d3
2 changed files with 22 additions and 19 deletions

View File

@@ -36,7 +36,8 @@ class TestOpsUtils(TestCaseMixin, unittest.TestCase):
self.assertClose(to_np(x), to_np(x_noise), atol=10 * noise_std)
with self.assertRaises(AssertionError) as context:
self.assertClose(to_np(x), to_np(x_noise), atol=0.1 * noise_std, msg=msg)
self.assertTrue(msg in str(context.exception))
self.assertIn(msg, str(context.exception))
self.assertIn("Not close", str(context.exception))
# test relative tolerance
assert torch.allclose(x, x_noise, rtol=100 * noise_std)