[TIP] One more question on fixture ordering!!
arun kali raja
arunsep886 at gmail.com
Mon Apr 23 10:13:16 PDT 2018
Hi,
I have two fixtures defined in my conftest.py as autouse fixtures..
*@pytest.fixture(scope='module',autouse=True)*
*def myModFix(request):*
* print("In MyModFix..")*
* yield*
* print("Post MyModFix..")*
*@pytest.fixture(scope="function",autouse=True)*
*def myFuncFix(request,testModFix):*
* print("In myFuncModFix")*
* yield*
* print("Post myFuncModFix")*
My Testcase file will have some more fixture defined..
*@pytest.fixture(scope='module')*
*def testModFix(request):*
* print("In testModFix..")*
* yield*
* print("post testModFix..")*
*@pytest.fixture(scope='module')*
*def secondTestModFix(request):*
* print("In 2ndTestModFix..")*
* yield*
* print("post 2ndTestModFix..")*
All my testcase file will defenitely have *testModFix* fixture, which is
added as a dependency to myFuncFix. In this way i achieve my desired
ordering..
*myModFix*
*testModFix*
*myFuncFix*
But in certain cases i may have a second module level fixture defined like
the example shown above as *secondTestModFix**. *In this case the desired
ordering i want is
*myModFix*
*testModFix*
*secondTestModFix*
*myFuncFix*
But i not able to achieve this order even if i explicitly specify the
fixture order in the testcase:
*def test_values(myModFix, testModFix, secondTestModFix, myFuncFix):*
* assert True*
When i execute the above code my output is:
*$ pytest -vs tests/test_tc.py*
*================================================================ test
session starts
================================================================*
*platform linux2 -- Python 2.7.14, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 --
/usr/bin/python*
*cachedir: .cache*
*rootdir: /home/akr8986/PythonTries/perf, inifile:*
*plugins: xdist-1.22.2, forked-0.2*
*collected 1 item s*
*tests/test_tc.py::test_values In MyModFix..*
*In testModFix..*
*In myFuncModFix*
*In 2ndTestModFix..*
*PASSEDPost myFuncModFix*
*post 2ndTestModFix..*
*post testModFix..*
*Post MyModFix..*
Suppose i set autouse as False for myFuncModFix then the order specified in
the testcase is pickedup correctly.
*$ pytest -vs tests/test_tc.py*
*================================================================ test
session starts
================================================================*
*platform linux2 -- Python 2.7.14, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 --
/usr/bin/python*
*cachedir: .cache*
*rootdir: /home/akr8986/PythonTries/perf, inifile:*
*plugins: xdist-1.22.2, forked-0.2*
*collected 1 item s*
*tests/test_tc.py::test_values In MyModFix..*
*In testModFix..*
*In 2ndTestModFix..*
*In myFuncModFix*
*PASSEDPost myFuncModFix*
*post 2ndTestModFix..*
*post testModFix..*
*Post MyModFix..*
Why is the explicit order specified in the testcase not respected for
autouse fixtures??
--
Regards
Arun Kaliraja.B
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20180423/440a17bd/attachment.html>
More information about the testing-in-python
mailing list