[TIP] permutated parameters without nested decorators?
dpb dpb
dpb.mediamath at gmail.com
Fri Mar 20 17:38:03 PDT 2015
I like very much that by using multiple parametrization decorators I can
test the permutations of a number of argvalues sequences of different
lengths. Here is an example with argvalues sequences of cardinality 4, 3,
and 2, respectively:
# params.py
>
import pytest
>
@pytest.mark.parametrize('a', [i for i in range(1, 5)])
> @pytest.mark.parametrize('b', [i ** 3 for i in range(1, 4)])
> @pytest.mark.parametrize('c', [i ** 5 for i in range(1,
> 3)])
> def test_funcs(a, b, c):
> assert (a + b) ** 2 != c ** 2
>
All 24 permutations run once:
$ py.test params.py
> ============================= test session starts
> ==============================
> platform darwin -- Python 3.4.2 -- py-1.4.26 -- pytest-2.6.4
> collected 24 items
>
> params/param5.py ........................
>
> ========================== 24 passed in 0.03 seconds
> ===========================
> $
>
But I wonder if there is a way to do this in a single expression, rather
than as nested decorators.
- dpb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150320/98e02080/attachment.htm>
More information about the testing-in-python
mailing list