Skipping decorators in unit tests

Cameron Simpson cs at zip.com.au
Fri Oct 11 02:40:05 EDT 2013


On 11Oct2013 05:51, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> On Fri, 11 Oct 2013 15:36:29 +1100, Cameron Simpson wrote:
> > But is it reliable? Will it work on any decorated function?
> 
> *Any* decorated function? No, of course not, since decorators can do 
> anything they like: [... examples ...]

That was what I thought; I was pretty sure I could quite reasonably
write all sorts of decorators this wouldn't work with.

> So consider this a *cooperative* undecorator. It can only undecorate 
> things that are decorated the way you expect them to be decorated. 

Fine.

And that is why I wrote my example as I did; I'd rather expose the
inner function by name if it is to be tested rather than write a
somewhat opaque special function that relies on all my decorators
following the same internal scheme. I'd only have to forget in the
frenzy of writing some special decorator to have my tests break
(or, worse, test the wrong thing).

So, for me, _if_ I intend to test the inner function alone, it is
worth the trade off of an extra name to avoid any need for special
knowledge of the inner workings of the decorators.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

A childproof cap is a Gordian knot to any adult who drinks.  ______ wrote
that he had seen the best minds of his generation destroyed by madness. I
have seen the best minds of mine go at a bottle of aspirin with a ball-peen
hammer. - P.J. O'Rourke



More information about the Python-list mailing list