Is it possible to order tests the way, that test A will go first, then test B go second and then test A will go again as third? I am using pytest-order lib.
Tech stack: Python 3.8.5, pytest 6.1.0, pytest-order 1.0.1
Here is the code used:
import logging
import pytest
@pytest.mark.order(2)
def test_a():
logging.info('test_a')
pass
@pytest.mark.order(1)
@pytest.mark.order(3)
def test_b():
logging.info('test_b')
pass
But test B is not executed third time. Only once as first one due to the two order marks.
Output:
=================== test session starts ==================
collecting ... collected 2 items
test.py::test_a PASSED [ 50%]
test.py::test_b PASSED [100%]
=================== 2 passed in 0.07s ===================
Actually
pytest-order
does not allow to add twoorder
marks. However I came up with some solution for you.You can resolve this syntax using pytest_generate_tests pytest hook. Just add it to your
conftest.py
file.Example below will read all
pytest.mark.order
marks and make parametrized test out of it (if more than 1 order mark was provided). It adds parameter calledorder
which stores arguments specified inpytest.mark.order
.conftest.py
test_order.py
pytest test_order.py -v
OutputAs you can see, all tests ran in defined order.
UPD
I have updated hook to make it compatible with other features of
pytest-order
. Also I have created PR in pytest-order GitHub repo.