run code when unit test assert fails [closed]
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm using assertEquals() from unittest.TestCase . What I want to do now is to call a function and do something there when the assertion fails, I wonder if there's a way of doing this? In general you shouldn't do it, but if you really want to, here is a simple example: import unittest def testFailed(): print("test failed") class T(unittest.TestCase): def test_x(self): try: self.assertTrue(False)