[TIP] Can you mock a function that has a decorator applies to it?

Julian Berman julian at grayvines.com
Wed Jul 4 10:50:28 PDT 2012

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?
> Thanks.
> John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120704/e0def27c/attachment.htm>

More information about the testing-in-python mailing list