<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.inbox-inbox-inbox-inbox-apple-converted-space
        {mso-style-name:inbox-inbox-inbox-inbox-apple-converted-space;}
span.inbox-inbox-inbox-inbox-inbox-inbox-inbox-inbox-apple-converted-space
        {mso-style-name:inbox-inbox-inbox-inbox-inbox-inbox-inbox-inbox-apple-converted-space;}
span.inbox-inbox-apple-converted-space
        {mso-style-name:inbox-inbox-apple-converted-space;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1027" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">List as default argument might not work as you expect (it is common Python gotcha):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><a href="http://docs.python-guide.org/en/latest/writing/gotchas/">http://docs.python-guide.org/en/latest/writing/gotchas/</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">So if you want to exploit such “static” biding, you are fine, but be aware what you are doing.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Just my $0.02, when I’ve seen mutable default argument it raised a red flag in code review
</span><span style="font-size:11.0pt;font-family:Wingdings;color:#1F497D">J</span><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter" />
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0" />
<v:f eqn="sum @0 1 0" />
<v:f eqn="sum 0 0 @1" />
<v:f eqn="prod @2 1 2" />
<v:f eqn="prod @3 21600 pixelWidth" />
<v:f eqn="prod @3 21600 pixelHeight" />
<v:f eqn="sum @0 0 1" />
<v:f eqn="prod @6 1 2" />
<v:f eqn="prod @7 21600 pixelWidth" />
<v:f eqn="sum @8 21600 0" />
<v:f eqn="prod @7 21600 pixelHeight" />
<v:f eqn="sum @10 21600 0" />
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" />
<o:lock v:ext="edit" aspectratio="t" />
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_s1026" type="#_x0000_t75" style='position:absolute;margin-left:0;margin-top:0;width:141pt;height:85.9pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:top;mso-position-vertical-relative:line;mso-width-percent:0;mso-height-percent:0;mso-width-relative:margin;mso-height-relative:margin' o:allowincell="f" o:allowoverlap="f">
<v:imagedata src="cid:image001.png@01D23FFD.95E31A10" o:title="" croptop="-23432f" cropbottom="-102842f" cropright="-5682f" />
<w:wrap type="square" anchory="line"/>
<w:anchorlock/>
</v:shape><![endif]--><![if !vml]><img width="188" height="115" src="cid:image002.png@01D23FFD.F94C7920" align="left" hspace="12" v:shapes="Picture_x0020_1"><![endif]><a name="AllText"></a><a name="EName"></a><b><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#231F20">Peter
 Masiar<span style="letter-spacing:.1pt"> </span></span></b><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#231F20">/ Sr Software Developer<span style="letter-spacing:-.4pt">
</span>/ ARINC Direct<br>
<span style="position:relative;top:.5pt;mso-text-raise:-.5pt">Information Management Services</span><br>
2551 Riva Road, Annapolis, MD 21401&nbsp; USA<br>
Phone:<span style="letter-spacing:-.35pt"> </span>&#43;1 410-573-3363 / Fax: &#43;1 410-266-2266<br>
<a name="Email"></a>pmasiar@arinc.com - </span><a href="http://www.rockwellcollins.com/"><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#231F20;text-decoration:none">ww<span style="letter-spacing:-.35pt">w</span>.rockwellcollins.com</span></a><span style="font-size:10.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#231F20"><br>
<br>
</span><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> testing-in-python-bounces@lists.idyll.org [mailto:testing-in-python-bounces@lists.idyll.org]
<b>On Behalf Of </b>oliver<br>
<b>Sent:</b> Wednesday, November 16, 2016 11:12 AM<br>
<b>To:</b> Bruno Oliveira; Florian Bruhin; testing-in-python@lists.idyll.org<br>
<b>Subject:</b> Re: [TIP] configure a pytest fixture<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, 16 Nov 2016 at 08:00 Bruno Oliveira &lt;<a href="mailto:nicoddemus@gmail.com">nicoddemus@gmail.com</a>&gt; wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal">On Wed, Nov 16, 2016 at 10:56 AM oliver &lt;<a href="mailto:oliver.schoenborn@gmail.com" target="_blank">oliver.schoenborn@gmail.com</a>&gt; wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Nov 16, 2016, 00:23 Florian Bruhin &lt;<a href="mailto:me@the-compiler.org" target="_blank">me@the-compiler.org</a>&gt; wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi,<br>
<br>
* oliver &lt;<a href="mailto:oliver.schoenborn@gmail.com" target="_blank">oliver.schoenborn@gmail.com</a>&gt; [2016-11-16 02:32:04 &#43;0000]:<br>
&gt; Thanks for the reply Bruno. I've used something like that in some fixtures<br>
&gt; (actually returning a closure / lambda which, when called from the test,<br>
&gt; returns a configured object), but it seems a little counter-intuitive (the<br>
&gt; premise being that fixtures return objects ready to be used). How about<br>
&gt; overloading the item operator [], so &quot;def test(fixture[a,b])&quot; would be<br>
&gt; implemented in a similar way to annotations like &quot;Map[str, int]&quot; but<br>
&gt; fixture[a,b] would allow the fixture function to receive a, b as<br>
&gt; parameters.<br>
<br>
That's invalid Python syntax - fixture is an argument name here, not<br>
an object.<o:p></o:p></p>
</blockquote>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Ah yes, rats! Then how about via a default value, this could easily be introspected by pytest:&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">def test(fixture=a): would call fixture(a)&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">def test(fixture=[a,b]): would call fixture(a, b) <o:p></o:p></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Not sure if that's not abusing the syntax and confusing to some, after all `fixture=1` seems like `fixture` would be `1`, but in fact could be anything returned by the fixture.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">My opinion is that I would not be a big fan of this.<o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">If someone can understand that declaring an argument is actually going to make the argument have the return value of the function that has the name of the argument, they will certainly understand that for fixtures, the default value is
 the args to the fixture. And there is no ambiguity, because if the fixture is not declared it is not available to the function (an auto-fixture cannot be configured). Perhaps the non-list version is not necessary:&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"># fixture will have return value of fixture(123.&nbsp;<span class="inbox-inbox-inbox-inbox-apple-converted-space">&nbsp;</span>'some string'):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">def test(fixture=[123, 'string']):&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Another option that would allow some autoused fixtures to be configured (scope must be compatible) would be a special pytest function. So given the following:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"># can be configured if desired:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">@pytest.fixture(autouse=True, scope='method')<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">def autofixture(arg1=456): &nbsp;&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp;...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">then&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"># fixture will have return value of fixture(123.&nbsp;<span class="inbox-inbox-inbox-inbox-inbox-inbox-inbox-inbox-apple-converted-space">&nbsp;</span>'some string'), and&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># autofixture for this method will be side-effects of call to autofixture(456)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">@pytest.config_fixtures(fixture=[123, 'string'])<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">def test1(fixture):&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp;...<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"># autofixture for this method will be side-effects of call to autofixture(789)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">@pytest.config_fixtures(autofixture=[789])<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">def test2():&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp;...<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">It's a bit more wordy than the default value approach, but still much better than using a marker because no boiler-plate for me to write.<span class="inbox-inbox-apple-converted-space">&nbsp;</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><span class="inbox-inbox-apple-converted-space">Oliver</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">Oliver<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>