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


Groups > comp.lang.python > #56627

Re: Skipping decorators in unit tests

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'preferably': 0.05; 'attribute': 0.07; 'decorator': 0.09; 'function,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tests,': 0.09; 'wrapped': 0.09; 'wrapper': 0.09; 'jan': 0.12; 'assume': 0.14; '10:00': 0.16; 'gilles': 0.16; 'modules.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wraps': 0.16; 'wrote:': 0.18; 'library': 0.18; 'app': 0.19; 'packages.': 0.19; 'header:User-Agent:1': 0.23; 'decorators': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; '"remove': 0.31; 'maybe': 0.34; 'classes': 0.35; 'test': 0.35; 'but': 0.35; 'add': 0.35; 'unit': 0.37; 'two': 0.37; 'depends': 0.38; 'easiest': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'received:173': 0.61; 'received:fios.verizon.net': 0.84; 'responses': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Skipping decorators in unit tests
Date Thu, 10 Oct 2013 21:12:47 -0400
References <2490050c-61d9-4bfd-bdd5-921e2f95a44b@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0
In-Reply-To <2490050c-61d9-4bfd-bdd5-921e2f95a44b@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.974.1381453982.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1381453982 news.xs4all.nl 15890 [2001:888:2000:d::a6]:58019
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:56627

Show key headers only | View raw


On 10/10/2013 10:00 AM, Gilles Lenfant wrote:

To add to the other two responses so far...

> (explaining the title) : my app has functions and methods (and maybe classes in the future) that are decorated by decorators provided by the standard library or 3rd party packages.
>
> But I need to test "undecorated" functions and methods in my unit tests, preferably without adding "special stuffs" in my target tested modules.

Let's assume that the decorator wraps the function in a way that the 
wrapper has a reference to the original function, so it does not disappear.

> Can someone point out good practices or dedicated tools that "remove temporarily" the decorations.

The easiest thing would be to have the decorator add the original 
function as an attribute .wrapped to the wrapper. Then test foo.wrapped. 
If you do not like this 'special stuff', then you would have to 
introspect the wrapper to access the wrapped function. How to do that 
depends on the wrapper.

-- 
Terry Jan Reedy

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


Thread

Skipping decorators in unit tests Gilles Lenfant <gilles.lenfant@gmail.com> - 2013-10-10 07:00 -0700
  Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 09:12 +1100
    Re: Skipping decorators in unit tests Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 02:55 +0000
      Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-11 14:13 +1100
        Re: Skipping decorators in unit tests Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 04:36 +0000
          Re: Skipping decorators in unit tests Terry Reedy <tjreedy@udel.edu> - 2013-10-11 04:23 -0400
      Re: Skipping decorators in unit tests Ben Finney <ben+python@benfinney.id.au> - 2013-10-11 14:42 +1100
      Re: Skipping decorators in unit tests Terry Reedy <tjreedy@udel.edu> - 2013-10-11 04:17 -0400
      Re: Skipping decorators in unit tests Terry Reedy <tjreedy@udel.edu> - 2013-10-11 04:25 -0400
      Re: Skipping decorators in unit tests Terry Reedy <tjreedy@udel.edu> - 2013-10-11 04:32 -0400
      Re: Skipping decorators in unit tests Ethan Furman <ethan@stoneleaf.us> - 2013-10-11 10:51 -0700
  Re: Skipping decorators in unit tests Ned Batchelder <ned@nedbatchelder.com> - 2013-10-10 19:44 -0400
  Re: Skipping decorators in unit tests Terry Reedy <tjreedy@udel.edu> - 2013-10-10 21:12 -0400
  Re: Skipping decorators in unit tests Gilles Lenfant <gilles.lenfant@gmail.com> - 2013-10-11 02:37 -0700
    Re: Skipping decorators in unit tests Cameron Simpson <cs@zip.com.au> - 2013-10-12 08:38 +1100

csiph-web