Let’s say I have the following:
def with_connection(f):
def decorated(*args, **kwargs):
f(get_connection(...), *args, **kwargs)
return decorated
@with_connection
def spam(connection):
# Do something
I want to test the spam function without going through the hassle of setting up a connection (or whatever the decorator is doing).
Given spam, how do I strip the decorator from it and get the underlying “undecorated” function?
In the general case, you can’t, because
is equivalent to
which means that the “original” spam might not even exist anymore. A (not too pretty) hack would be this: