[pytest-dev] Fixtures and test cases parametrization -- the clever way

Holger Krekel holger at merlinux.eu
Sun Feb 7 03:42:38 EST 2016


Hi Gonzalo, 

Probably the pytest_generate_tests hook helps, see http://pytest.org/latest/example/parametrize.html#generating-parameters-combinations-depending-on-command-line

Cheers holger

On February 7, 2016 4:53:39 AM GMT+01:00, Goncalo Morgado <goncalo.magno at gmail.com> wrote:
>Hi,
>
>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
>the
>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
>*.mark.parametrize()*
>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,
>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
>Go
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>pytest-dev mailing list
>pytest-dev at python.org
>https://mail.python.org/mailman/listinfo/pytest-dev

-- 
Sent using mobile touch keys, increased chances for errors and misunderstandings. Enjoy! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20160207/6fd16240/attachment.html>


More information about the pytest-dev mailing list