Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56653

Re: Skipping decorators in unit tests

Date 2013-10-11 17:40 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: Skipping decorators in unit tests
References <525791e2$0$29984$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.987.1381473621.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 11Oct2013 05:51, Steven D'Aprano <steve+comp.lang.python@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@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 15:36 +1100
  Re: Skipping decorators in unit tests Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 05:51 +0000
    Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 17:40 +1100

csiph-web