I am trying to print the item that rose as exception when I run my unit tests. For example:
def test_string(self):
my_str = "new string"
self.assertTrue(len(my_str) == 5)
This is a very simplified example but it shows what I am trying to achieve. I want, in that case, for the test to print "new string" after I get 'F'.
In regular assert I can achieve that by doing:
assert (len(my_str) == 5), "new string"
But when using unittest it won't work.
Is there a way to do that with unittest ?
self.assertEqual(len(my_str), 5). Also, use pytest if you can, then you can write regular asserts and it'll still show you the failing values.