<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(&#39;a, b, c&#39;, 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&#39;s interesting that because of the way Metafunc.parametrize is written (I&#39;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">&lt;<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>&gt;</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>
&gt; I like very much that by using multiple parametrization decorators I can<br>
&gt; test the permutations of a number of argvalues sequences of different<br>
&gt; lengths. Here is an example with argvalues sequences of cardinality 4, 3,<br>
&gt; and 2, respectively:<br>
&gt;<br>
&gt; # params.py<br>
&gt; &gt;<br>
&gt; import pytest<br>
&gt; &gt;<br>
&gt; @pytest.mark.parametrize(&#39;a&#39;, [i for i in range(1, 5)])<br>
&gt; &gt; @pytest.mark.parametrize(&#39;b&#39;, [i ** 3 for i in range(1, 4)])<br>
&gt; &gt; @pytest.mark.parametrize(&#39;c&#39;, [i ** 5 for i in range(1,<br>
&gt; &gt; 3)])<br>
&gt; &gt; def test_funcs(a, b, c):<br>
&gt; &gt;     assert (a + b) ** 2 != c ** 2<br>
&gt; &gt;<br>
&gt;<br>
&gt; All 24 permutations run once:<br>
&gt;<br>
&gt; $ py.test params.py<br>
&gt; &gt; ============================= test session starts<br>
&gt; &gt; ==============================<br>
&gt; &gt; platform darwin -- Python 3.4.2 -- py-1.4.26 -- pytest-2.6.4<br>
&gt; &gt; collected 24 items<br>
&gt; &gt;<br>
&gt; &gt; params/param5.py ........................<br>
&gt; &gt;<br>
&gt; &gt; ========================== 24 passed in 0.03 seconds<br>
&gt; &gt; ===========================<br>
&gt; &gt; $<br>
&gt; &gt;<br>
&gt;<br>
&gt; But I wonder if there is a way to do this in a single expression, rather<br>
&gt; than as nested decorators.<br>
<br>
</div></div>Maybe something like:<br>
<br>
    @pytest.mark.parametrize(&quot;a,b,c&quot;, 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&#39;t think it&#39;s much more readable.<br>
<br>
best,<br>
holger<br>
</blockquote></div><br></div>
</div></div></div><br></div>