I'd like to a log some information to a file/database every time assert is invoked. Is there a way to override assert or register some sort of callback function to do this, every time assert is invoked?
Regards Sharad
I'd like to a log some information to a file/database every time assert is invoked. Is there a way to override assert or register some sort of callback function to do this, every time assert is invoked?
Regards Sharad
Try overload the AssertionError
instead of assert
. The original assertion error is available in exceptions module in python2 and builtins module in python3.
import exceptionsclass AssertionError:def __init__(self, *args, **kwargs):print("Log me!")raise exceptions.AssertionError