[py-dev] Generic funcarg hook

Floris Bruynooghe flub at devork.be
Sat Aug 7 11:52:24 CEST 2010


Hi

I was talking to ronny on IRC about wanting a generic funcarg hook and
he asked me to post my use case here as you are still thinking about
the API for it.  Since there is no generic funcarg hook now this is
how I currently create the tests:


def pytest_funcarg__tdata(request):
    fname = os.path.join(DATADIR, requst.function.__name__+'.ext')
    with file(fname) as fd:
        obj = fd.read()
    return obj

def test_spam(tdata):
    assert func_under_test(tdata) == 'foo'

def test_eggs(tdata):
    assert func_under_test(tdata) == 'bar'


Before I started writing it this way I was looking for a generic
funcarg hook since I think this would have been clearer if I could
have used "spam" and "eggs" as funcargs and still create the object
for them from one function rather then having to spell it out for each
one.  So I'm hoping that in a future version you might add an API to
do allow something like this.

-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org



More information about the Pytest-dev mailing list