I based my code around this : How to execute code only on test failures with python unittest2?
But instead of a screenshot I want to call an API to say the same thing as the assert when a test fail. I can use the stacktrace as a message it's fine (if possible). I tried with traceback module but the stacktrace was empty.
@property
def failureException(self):
class MyFailureException(AssertionError):
def __init__(self_, *args, **kwargs):
test_id = os.path.basename(__file__).split('_')[1] # file has the id for the API
client = getClient()
client.test_failed(test_id, comment=str('Failed'))
return super(MyFailureException, self_).__init__(*args, **kwargs)
MyFailureException.__name__ = AssertionError.__name__
return MyFailureException
if I use the args, I get : True is not False, for assertFalse. Which is not helpful.