[py-dev] Using funcargs with decorators
Sebastian Rahlf
basti at redtoad.de
Thu Oct 11 11:47:03 CEST 2012
Hi!
At work we use a decorator @rollback on selected test functions which
will rollback any db changes made during that test.
I've recently started using pytest's dependency injection for a few
use cases, both with @pytest.mark.parametrize(...) and the
pytest_funcarg__XXX hook.
Unfortunately, this clashes with our decorated test functions.
How can I make this work?
My first idea was using a custom marker, say @pytest.mark.rollback and
do something like:
def rollback(meth):
"""Original rollback function"""
...
def pytest_runtest_setup(item):
if not isinstance(item, pytest.Function):
return
if hasattr(item.obj, 'rollback'):
item = rollback(item)
Would an approach like this actually work?
Sebastian
P.S. I've posted this to stackoverflow before I remembered that there
is a mailing list
http://stackoverflow.com/questions/12836134/pytest-using-dependency-injection-with-decorators
More information about the Pytest-dev
mailing list