[TIP] fixture ordering and dynamically adding fixtures to Testcases

Floris Bruynooghe flub at devork.be
Mon Jan 15 13:17:43 PST 2018


It seems Bruno's reply got lost somewhere...

On Sat 13 Jan 2018 at 22:38 +0530, arun kali raja wrote:
> 1. I have a .py file where i have defined two Autouse fixtures..
> fixtureMod_1 is module scoped and fixtureFunc_1 is function scoped.. Now in
> conftest.py i have imported these two fixtures.. in my test_x.py i have a
> another module scoped fixture say fixtureMod_2..The order of execution of
> fixture seems to be fixtureMod_1,fixtureFunc_1 and then fixtureMod_2.. isnt
> module level fixtures supposed to be executed before function level
> fixtures?? isnt that how scopes are ordered.. i am able to solve the issues
> by giving fixtureMod_2  as a dependency to fixtureFunc_1.. but still i am
> trying to understand why pytest respects the scope ordering in this case..
> does the order of sourcing the fixture override the scope based ordering??

If I understand this correct then you have something like this:

   def fixtureMod_1():

   def fixtureFunc_1():

   from foo import fixtureMod_1
   from foo import fixtureFun_1

   def fixtureMod_2():

   def test_foo(fixtureMod_1, fixtureFunc_1, fixtureMod_2):

More information about the testing-in-python mailing list