<div dir="ltr">Hi Bruno/Floris,<div><br></div><div>Thanks a lot for the insight.</div><div><br></div><div>i was trying out few things and found these..</div><div><br></div><div>1. Ordering fixtures:</div><div>     Suppose the user wants to impose the ordering of fixtures in a certain way then he can do it via the <b><i>pytest_generate_tests(metafunc)</i></b> hook:</div><div><br></div><div>    the <b><i>metafunc</i></b> object has a member variable <b><i>fixturenames</i></b>.. that is the list of fixtures that are gona be executed for this test.</div><div><br></div><div>    the user can reorder it as he wishes. </div><div> </div><div>    In my case i have some autoUse fixtures, but they have some dependency fixtures  which are not autoUse.. so fixtureA(autoUse) is dependent on fixtureB( not autoUse). So only if fixtureB is available i want to include fixtureA otherwise i dont want to use fixtureA at all.. i Can achieve this by checking contents of the list and making appropriate decisions to remove invalid fixtures too..</div><div><br></div><div>   Now say i want to call all my session fixtures , then module, then class and then function fixtures, how do i know which is what? bcoz the <b><i>fixturenames</i></b> variable is just a list of fixture names(strings)..</div><div><br></div><div>   the solution is to check the fixture information from the <i style="font-weight:bold">metafunc._arg2fixturedefs </i>dictionary. the dictionary has fixture name as key and a tuple as a value. the tuple has a object FixtureDef which scope related information.</div><div><br></div><div>Question:</div><div>    Is this a right way to do? or just a hacky way to make things work?</div><div><br></div><div>Curious question:</div><div>   why is the values in the <b><i>_arg2fixturedefs</i></b> a tuple?? can a fixture have more than one definitions??</div><div><br></div><div>2. Adding fixtures dynamically at run time.   </div><div><br></div><div>    I am trying to create a library of fixtures which will provide a standard set of functionalities.. the user has to add those in his testcase and then parameterise them according to his usecase.</div><div> </div><div>    Instead of the selecting the fixtures i want to give flexibility to specify the usecase in a marker with some parameters and then the dynamically add the fixtures.</div><div><br></div><div>    I think here too <b><i>pytest_generate_tests</i></b> is the right place to do such things...</div><div><br></div><div>    I was able to read the markers using <b><i>metafunc.function</i></b>  member variable and then add fixtures to the <b><i>metafunc.fixturenames</i></b> member variable..</div><div><br></div><div>    And the fixture got called at the time of execution too..</div><div><br></div><div>   Question:</div><div>        Suppose i want to create a fixture chain according to my use case i can do it by inserting them one after the other in the <b style="font-style:italic">fixturenames. </b>But suppose i want to access value returned by fixtureA in fixtureB i am not sure how to do it.. Becase in that case i have to add fixtureA as a dependency to fixtureB. I havent figured out that yet..<br></div><div><br></div><div>    Curious Question:</div><div>       The <i style="font-weight:bold">metafunc._arg2fixturedefs </i>variable i have mentioned above seems to be populated at the <i style="font-weight:bold">pytest_generate_tests </i>phase itself.. I am not sure how appending the fixture name at <b style="font-style:italic">pytest_generate_tests </b>even works.. i tried putting a breakpoint at <i style="font-weight:bold">pytests_itemcollected() </i>hook.. but even there it seems that the <i style="font-weight:bold">_arg2fixturedefs </i>doesnt  seem to have the entry for the newly added fixture.. So i am not sure yet how it works..</div><div><br></div><div><br></div><div>Regards</div><div>Arun Kaliraja.B</div><div>    </div></div><div class="gmail_extra"><br><div class="gmail_quote">On 16 January 2018 at 02:47, Floris Bruynooghe <span dir="ltr">&lt;<a href="mailto:flub@devork.be" target="_blank">flub@devork.be</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
It seems Bruno&#39;s reply got lost somewhere...<br>
<span class=""><br>
On Sat 13 Jan 2018 at 22:38 +0530, arun kali raja wrote:<br>
&gt; 1. I have a .py file where i have defined two Autouse fixtures..<br>
&gt; fixtureMod_1 is module scoped and fixtureFunc_1 is function scoped.. Now in<br>
&gt; conftest.py i have imported these two fixtures.. in my test_x.py i have a<br>
&gt; another module scoped fixture say fixtureMod_2..The order of execution of<br>
&gt; fixture seems to be fixtureMod_1,fixtureFunc_1 and then fixtureMod_2.. isnt<br>
&gt; module level fixtures supposed to be executed before function level<br>
&gt; fixtures?? isnt that how scopes are ordered.. i am able to solve the issues<br>
&gt; by giving fixtureMod_2  as a dependency to fixtureFunc_1.. but still i am<br>
&gt; trying to understand why pytest respects the scope ordering in this case..<br>
&gt; does the order of sourcing the fixture override the scope based ordering??<br>
<br>
</span>If I understand this correct then you have something like this:<br>
<br>
foo.py:<br>
   @pytest.fixture<br>
   def fixtureMod_1():<br>
       pass<br>
<br>
   @pytest.fixture<br>
   def fixtureFunc_1():<br>
       pass<br>
<br>
conftest.py:<br>
   from foo import fixtureMod_1<br>
   from foo import fixtureFun_1<br>
<br>
test_x.py:<br>
<br>
   @pytest.fixture<br>
   def fixtureMod_2():<br>
       pass<br>
<br>
   def test_foo(fixtureMod_1, fixtureFunc_1, fixtureMod_2):<br>
       pass<br>
<br>