2011/5/1 Ronny Pfannschmidt <ronny.pfannschm...@gmx.de>

> On Sun, 2011-05-01 at 11:59 +0200, Baptiste Lepilleur wrote:
> ...
> > @parametrized( _generate_property_validation_tests, ['good_values'] )
> > def test_property_validation_good_values( scenario_type, dbo_class,
> > value, good_value ):
> >    ...
> >
> >
> > The parametrized decorator would
> > call _generate_property_validation_tests( metafunc, ['good_values'] ).
> >
> >
> > Is there a way to do that?
> you can use the pytest.mark  tool to make a decorator which annotates
> the value types nicely
>

Great, this is exactly what I wanted!

The pytest_generate_tests function is now generic:

def pytest_generate_tests(metafunc):
    if hasattr( metafunc.function, 'parametrized' ):
        args = metafunc.function.parametrized.args
        kwargs = metafunc.function.parametrized.kwargs
        test_generator, args = args[0], args[1:]
        test_generator( metafunc, *args, **kwargs )

And the parameter generator function can be specified as I wanted:

@py.test.mark.parametrized( _generate_property_validation_tests,
['good_values'] )
def test_property_validation_good_values( dbo_class, value, good_value ):
   ...

Here is the source:
http://pastebin.com/kfgvM7L9

The only pitfall to be aware of is that you must always provide two
parameters to @py.test.mark.parametrized otherwise MarkDecorator will think
that the first parameter, which is callable, must be decorated.

Thanks a lot for your help,
Baptiste.


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

Reply via email to