<div dir="ltr">Ah, sorry — neglected to reply to list.- dpb<br><div class="gmail_quote"><br></div><div class="gmail_quote">---------- Forwarded message ----------<br>Date: Sun, Mar 22, 2015 at 10:01 PM<br><br><div dir="ltr">Thanks. I think it can be made considerably more readable as<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="monospace, monospace">import itertools<br></font><font face="monospace, monospace">parameters = itertools.product(range(1,5),<br></font><span class=""><font face="monospace, monospace"> [i**3 for i in range(1,4)],<br></font><font face="monospace, monospace"> [i**5 for i in range(1,3)])<br></font><font face="monospace, monospace"> <br></font></span><font face="monospace, monospace">@pytest.mark.parametrize('a, b, c', list(parameters))<br></font><span class=""><font face="monospace, monospace">def test_funcs(a, b, c):<br></font><font face="monospace, monospace"> assert (a + b) ** 2 != c ** 2 </font></span></blockquote></div><div><br></div><div>(Py3K.) It's interesting that because of the way Metafunc.parametrize is written (I'm looking at <a href="https://bitbucket.org/pytest-dev/pytest/src/39361b33346e784e4f6359dbdba9c9957a8e4cd7/_pytest/python.py" target="_blank">https://bitbucket.org/pytest-dev/pytest/src/39361b33346e784e4f6359dbdba9c9957a8e4cd7/_pytest/python.py</a>, lines 823-831, argvalues is fully expanded into a list before test functions are run, so there seems to be no advantage in using a generator for argvalues. </div><span class="HOEnZb"><font color="#888888"><div><br></div><div>- dpb</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 21, 2015 at 10:35 AM, holger krekel <span dir="ltr"><<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Fri, Mar 20, 2015 at 20:38 -0400, dpb dpb wrote:<br>
> I like very much that by using multiple parametrization decorators I can<br>
> test the permutations of a number of argvalues sequences of different<br>
> lengths. Here is an example with argvalues sequences of cardinality 4, 3,<br>
> and 2, respectively:<br>
><br>
> # params.py<br>
> ><br>
> import pytest<br>
> ><br>
> @pytest.mark.parametrize('a', [i for i in range(1, 5)])<br>
> > @pytest.mark.parametrize('b', [i ** 3 for i in range(1, 4)])<br>
> > @pytest.mark.parametrize('c', [i ** 5 for i in range(1,<br>
> > 3)])<br>
> > def test_funcs(a, b, c):<br>
> > assert (a + b) ** 2 != c ** 2<br>
> ><br>
><br>
> All 24 permutations run once:<br>
><br>
> $ py.test params.py<br>
> > ============================= test session starts<br>
> > ==============================<br>
> > platform darwin -- Python 3.4.2 -- py-1.4.26 -- pytest-2.6.4<br>
> > collected 24 items<br>
> ><br>
> > params/param5.py ........................<br>
> ><br>
> > ========================== 24 passed in 0.03 seconds<br>
> > ===========================<br>
> > $<br>
> ><br>
><br>
> But I wonder if there is a way to do this in a single expression, rather<br>
> than as nested decorators.<br>
<br>
</div></div>Maybe something like:<br>
<br>
@pytest.mark.parametrize("a,b,c", list(itertools.product(<br>
range(1,5),<br>
[i**3 for i in range(1,4)],<br>
[i**5 for i in range(1,3)])))<br>
<br>
although i don't think it's much more readable.<br>
<br>
best,<br>
holger<br>
</blockquote></div><br></div>
</div></div></div><br></div>