No subject

Tue Jan 16 06:10:05 PST 2018

The scopes are used to know when the setup and teardown of each fixture<br>
needs to run, e.g. with a function-scope the fixture will be created for<br=
just before a single test which needs it and destroyed right after this<br>
test has run.<br>
For a module scope the fixture gets only created once for<br>
all tests in a module.=C2=A0 So if multiple tests in test_x require either<=
fixtureMod_1 or fixtureMod_2 their setup and teardown will only be<br>
executed once.<br>
So scopes have nothing to do with ordering.<br>
As you discovered if you declare dependencies on fixtures then the<br>
ordering will start to be defined:<br>
def fixtureFunc_1(fixtureMod_2):<br>
=C2=A0 =C2=A0 pass<br>
This will ensure that fixtureMod_2 is created first.=C2=A0 It&#39;s good th=
this dependency needs to be explicit in your code.=C2=A0 However be careful=
in general to not over-use dependencies like this, e.g. if the only<br>
reason you declare fixtureMod_2 is to use as a dependency in<br>
fixtureFunc_1 then maybe fixtureMod_2 shouldn&#39;t be a fixture at all.<br=
As another aside btw, I always *strongy* advice against ever importing<br>
fixtures.=C2=A0 The semantics of it are very confusing (this was probably a=
design mistake) so instead always move the fixture to the right<br>
location, i.e. your file.<br>
<span class=3D""><br>
&gt; 2. I have one usecase where i want to dynamically create a fixture cha=
&gt; say i mark by testcase with useCaseA and that translates to an orderin=
g of<br>
&gt; fixture.. can i add a fixture to a testcase at run time.. at<br>
&gt; pytest_generate_test phase or pytest_configure phase?? i found a metho=
&gt; called add_marker to add a marker at runt time.. since fixtures can al=
so be<br>
&gt; added via markers i was trying to explore if can use that method but i=
&gt; doesnt accept any parameters.. any way i can achieve this??<br>
</span>Here I&#39;m somewhat lost with your example, I think you have this:=
def test_foo():<br>
=C2=A0 =C2=A0 pass<br>
But I&#39;m afraid you&#39;ll have to give me more info on how tha translat=
es to<br>
fixtures in your implementation.<br>
With respect to dynamically requested fixtures, this is usually done<br>
using request.getfixturevalue() [0].=C2=A0 However, and this is where<br>
personal opinions differ, my advice is to avoid this if you possibly<br>
can.=C2=A0 And my opinion is also that this is always possible, e.g. a<br>
fixture can return instances of two different classes depending on the<br>
dynamic &quot;thing&quot;.<br>
Hope this helps,<br>
[0] <a href=3D"
etfixturevalue#_pytest.fixtures.FixtureRequest.getfixturevalue" rel=3D"nore=
ferrer" target=3D"_blank"><wbr>latest/
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">=E0=AE=85=E0=AE=A9=
=E0=AE=AA=E0=AE=BE. =E0=AE=85=E0=AE=B0=E0=AF=81=E0=AE=A3=E0=AF=8D =E0=AE=95=
=E0=AE=BE=E0=AE=B3=E0=AE=BF =E0=AE=B0=E0=AE=BE=E0=AE=9A=E0=AE=BE </div>


More information about the testing-in-python mailing list