[TIP] decorators in testing
Ben Finney
ben+python at benfinney.id.au
Sat Apr 4 05:37:00 PDT 2009
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():
# ...
--
\ “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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090404/397805a1/attachment.pgp
More information about the testing-in-python
mailing list