Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'preferably': 0.05; 'tests,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'b):': 0.16; 'behave': 0.16; 'forth.': 0.16; 'gilles': 0.16; 'heed': 0.16; 'modules.': 0.16; 'simpson': 0.16; 'do,': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'library': 0.18; 'all,': 0.19; 'app': 0.19; 'packages.': 0.19; 'solution.': 0.20; 'example': 0.22; 'cc:addr:python.org': 0.22; 'header:User- Agent:1': 0.23; "aren't": 0.24; 'decorators': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "i'm": 0.30; '"remove': 0.31; 'maybe': 0.34; 'classes': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'functions.': 0.36; "i'll": 0.36; 'unit': 0.37; 'pm,': 0.38; 'how': 0.40; 'skip:u 10': 0.60; 'information,': 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'anyone.': 0.74; 'imagination': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=7tRTOS1kMxkV/EVWoUAOtrT+MvKB5s8dmgM/PxYhUSo=; b=MY3HRo1tL3DuXsHw8M2k7D841+7CS7wTbNyleaYIMpS4yuwnlisHRUJook1yUqQWCD P9fgjcLxrFsZpospNb/1t3fjI0pxXybtGAfwojzXH8xw6heXyd0Kz5wdzS5OyTYjwDHc CKvJ8D+parO+5pYeFf9hvbO0B9XhKULgsdqL9pXFyDhFflZckHMoEGzq6eI6yt4gv3Zw Z2VyyDcXr2lGtumc62yLLdk8cGdbftpxDNPwTC3dzobR9Jn6ZOM68sYbdgVFRJEZGuQL VAh75l6lnwWBjIaYtmO8/lQFAEv92fJBGFN70IJx7lEi96qwT1ph6qF6vxxpbWsE6Q0k BEAA== X-Received: by 10.224.166.67 with SMTP id l3mr70753qay.39.1381448686439; Thu, 10 Oct 2013 16:44:46 -0700 (PDT) Sender: Ned Batchelder Date: Thu, 10 Oct 2013 19:44:45 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: gilles.lenfant@gmail.com Subject: Re: Skipping decorators in unit tests References: <2490050c-61d9-4bfd-bdd5-921e2f95a44b@googlegroups.com> <20131010221238.GA27082@cskk.homeip.net> In-Reply-To: <20131010221238.GA27082@cskk.homeip.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381448694 news.xs4all.nl 15972 [2001:888:2000:d::a6]:55499 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56617 On 10/10/13 6:12 PM, Cameron Simpson wrote: > On 10Oct2013 07:00, Gilles Lenfant wrote: >> (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. >> >> Can someone point out good practices or dedicated tools that "remove temporarily" the decorations. >> I pasted a small example of what I heed at http://pastebin.com/20CmHQ7Y > Speaking for myself, I would be include to recast this code: > > @absolutize > def addition(a, b): > return a + b > > into: > > def _addition(a, b): > return a + b > > addition = absolutize(_addition) > > Then you can unit test both _addition() and addition(). > > And so forth. > > Cheers, I have to admit I'm having a hard time understanding why you'd need to test the undecorated functions. After all, the undecorated functions aren't available to anyone. All that matters is how they behave with the decorators. But my imagination is weak: do you mind explaining more about what the functions do, what the decorators do, and why you need to test the undecorated functions? I'll learn something, and with more information, we might be able to find a better solution. --Ned.