[TIP] decorators in testing

Noah Gift noah.gift at gmail.com
Sat Apr 4 05:41:07 PDT 2009


On Sun, Apr 5, 2009 at 1:37 AM, Ben Finney
<ben+python at benfinney.id.au<ben%2Bpython at benfinney.id.au>
> wrote:

> Michael Gratton <michael at quuxo.com> writes:
>
> > In Python, a test class might look like:
> >
> > class Foo(object):
> >
> >     @before
> >     def newFoo(self): ...
> >
> >     @test
> >     def handleFrobnostication(self): ...
> >
> >     @after
> >     def destroyFoo(self): ...
>
> […]
>
> > Does anyone have an implementation of this for Python?
>
> ‘nose’ allows setup and teardown functions to be written, then used to
> decorate test functions:
>
> From nose import with_setup
>
> def blivet_setup():
>    # ...
>
> def blivet_teardown():
>    # ...
>
> @with_setup(blivet_setup, blivet_teardown)
> def test_frobnicates_the_blivet():
>    # ...


But this only works with tests that are functions correct?

>
>
> --
>  \             “I put contact lenses in my dog's eyes. They had little |
>  `\   pictures of cats on them. Then I took one out and he ran around |
> _o__)                                      in circles.” —Steven Wright |
> Ben Finney
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
>


-- 
Cheers,

Noah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/testing-in-python/attachments/20090405/bb260948/attachment-0001.htm 


More information about the testing-in-python mailing list