nose-devs/nose — Issue #251: Multiple with_setup() decorators do not work
Author: jpellerin
Created: 2011-12-14 16:05:22+00:00
State: closed

With nose 0.10.0, if I use multiple with_setup() decorators, only the first "wins".

If I say:
@with_setup(s1, t1)
@with_setup(s2, t2)
def test_me():
pass

The resulting call sequence is:
s1(), test_me(), s2().

The sequence should be:
s1(), s2(), test_me(), t2(), t1().

This can be easily fixed by implementing with_setup() using the make_decorator() already
present in nose.tools (the same way limit was implemented):

def with_setup(setup=None, teardown=None):
"""Decorator to add setup and/or teardown methods to a test function::

@with_setup(setup, teardown)
def test_something():
# ...

Note that `with_setup` is useful *only* for test functions, not for test
methods or inside of TestCase subclasses.
"""
def decorate(func, setup=setup, teardown=teardown):
def newfunc(*arg, **kw):
if setup:
setup()
try:
func(*arg, **kw)
finally:
if teardown:
teardown()
newfunc = make_decorator(func)(newfunc)
return newfunc
return decorate

Google Code Info:
Issue #: 151
Author: tles...@gmail.com
Created On: 2008-01-18T19:18:48.000Z
Closed On: 2008-03-28T02:29:12.000Z