@property
def failureException(self):


    class MyFailureException(AssertionError):

        def __init__(self_, *args, **kwargs):
            self.b.save_screenshot('%s.png' % self.id())
return super(MyFailureException, self_).__init__(*args, **kwargs)
MyFailureException.__name__ = AssertionError.__name__
return MyFailureException
How to execute code only on test failures with python unittest2?