[py-dev] Decorators and funcargs in py.test

Vyacheslav Rafalskiy rafalskiy at gmail.com
Mon May 30 21:17:32 CEST 2011

Hi Holger,

I am trying to make decorators work with test functions, which depend
on funcargs. As it stands, they don't.
Decorated functions lose funcargs. A workaround would be to decorate
an internal function like this:

def test_it(funcarg_it):
    def _test_it():
        # test it


This works, but it is not nice. I'd rather wrote a decorator like

def decorate_it(f):
    def _wrap_it(*args, **kwargs):
        # wrap f() here

    _wrap_it._varnames = _pytest.core.varnames(f)
    return _wrap_it

and apply it straight to the test function.

After examining the source code I even expected it to just work
(magically of course) but it didn't.
Do you think it is worthwhile? If so I can enter a feature request.


More information about the Pytest-dev mailing list