[pytest-dev] Fixtures and test cases parametrization -- the clever way
goncalo.magno at gmail.com
Sun Feb 7 19:29:13 EST 2016
Thanks for the reply.
Very useful! I am reconsidering the amount of tests I was trying to
parametrize in a single test case, and split it in multiple test_*
functions for different groups of tests. Also creating a fixture for
default parameters, those that are not parametrized get set by this fixture.
On Sun, Feb 7, 2016 at 8:53 AM, Florian Schulze <florian.schulze at gmx.net>
> Maybe https://pypi.python.org/pypi/hypothesis is a better fit for this
> than parametrization. At first it might seem a bit foreign (it felt so to
> me), but it allows you to test in very interesting ways and to find corner
> cases quickly. Just testing all the keys is pretty boring and most likely
> won't lead to errors, so it's pretty much a waste of your time and CPU time.
> Florian Schulze
> On 7 Feb 2016, at 4:53, Goncalo Morgado wrote:
>> Thank you for this great lib!
>> I have an app that takes a config file with key/value pairs, that I would
>> like to test thoroughly, i.e all possible combinations of parameters in
>> config file. I thought about taking advantage of the fixture
>> parametrization functionality pytest provides, but not sure how... and end
>> up with what I believe is a silly idea (please see example code below). I
>> say silly because I will end up with a huge amount of
>> entries and the test case function with a number of arguments... Any idea
>> on how to do this an elegant way?
>> *import* pytest
>> @pytest.mark.parametrize("key1", [0, 1, etc, etc])
>> @pytest.mark.parametrize("key2", [2, 3, etc, etc, etc])
>> @pytest.mark.parametrize("key3", [4, 5, etc, etc, etc, etc])
>> ... # an infinitiy amount of @pytest.mark.parametrize("keyN", [bla, bla,
>> *def* test_app_param_combination(key1, key2, key3, ....)
>> # implementation of the test
>> # run app with combination of key/value pair and check exit code
>> *assert* app_exit_code == 0
>> Many thanks
>> pytest-dev mailing list
>> pytest-dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pytest-dev