[TIP] Can you mock a function that has a decorator applies to it?
gokoproject at gmail.com
Wed Jul 4 11:06:33 PDT 2012
Okay... I guess I would have to add a line that references the undecorated
reference like this?
def decorated(*args, **kwargs):
print 'I am a decorator...'
print 'I am exiting decorator'
decorated._original = f
print "aFunction running"
if __name__ == '__main__':
On Wed, Jul 4, 2012 at 1:50 PM, Julian Berman <julian at grayvines.com> wrote:
> I'd probably expect you to mock out whatever the decorator is calling out
> to instead.
> Barring that there's not really a general way to retrieve the original
> function object off the decorated function without poking at its locals. At
> that point you'd probably be better off just storing an undecorated
> reference in your code to make it more testable.
> On Wednesday, July 4, 2012, John Wong wrote:
>> There are times when decorator really shine and I don't see a way to Mock
>> out the decorator. I know it replaces the current function.... is there a
>> way out of this?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python