[TIP] decorators in testing [was: cleanUp for unittest]

Olemis Lang olemis at gmail.com
Mon Apr 6 05:37:52 PDT 2009


On Sat, Apr 4, 2009 at 6:52 AM, Michael Gratton <michael at quuxo.com> wrote:
> On Fri, 2009-04-03 at 21:03 +0100, Michael Foord wrote:
>> Totally new subject - could you elaborate on what is meant by test
>> decorators, what they do and how they do it (usage rather than
>> implementation).
>
> JUnit 4 defines a set of method decorators for defining fixture set up
> and tear-down methods as well as actual test methods, rather relying on
> magic names. This is actually rather nifty and something I'd like to see
> in the Python testing universe.
>
> In Python, a test class might look like:
>
> class Foo(object):
>
>    @before
>    def newFoo(self): ...
>
>    @test
>    def handleFrobnostication(self): ...
>
>    @after
>    def destroyFoo(self): ...
>

A comment here ... perhaps we'r talking about two different things
here since the syntax for Py decorators are similar to Java
annotations, but semantics 'r different ... It is just a problem of
syntax and semantics, and also that the word «decorator» in Python
mean something, and in GoF catalog means another ;)

>
> The advantages include

I know all this may be helpful ... but I was talking about
TestDecorator class [1]_.

.. [1] JUnit TestDecorator class
        (http://junit.org/apidocs/junit/extensions/TestDecorator.html)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list