Hi Sebastian,

On Thu, Oct 11, 2012 at 11:47 +0200, Sebastian Rahlf wrote:
> 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?

I think so - probably you need to call "rollback(item.obj") though.

> 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

I answered there as well.

best,
holger


_______________________________________________
> py-dev mailing list
> py-dev@codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
> 
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to