I have a solution that works for test functions, using a custom decorator:
def with_named_setup(setup=None, teardown=None):
def wrap(f):
return with_setup(
lambda: setup(f.__name__) if (setup is not None) else None,
lambda: teardown(f.__name__) if (teardown is not None) else None)(f)
return wrap
@with_named_setup(setup_func, teardown_func)
def test_one():
pass
@with_named_setup(setup_func, teardown_func)
def test_two():
pass
This reuses the existing with_setup
decorator, but binds the name of the decorated function to the setup
and teardown
functions passed as parameters.