0

I have a test class that has one parametrized class and some tests inside of it, that each have their own parametrize method. I want the class to run all tests inside of it with one class parameter and only after all tests have finished, run the tests again with the second parameter. For e.g.: The code is like this:

@pytest.mark.parametrize("param_a",[1,2])
class TestTest():

    @pytest.mark.parametrize("param_b",[3,4])
    def test_1(self, param):
        pass

    @pytest.mark.parametrize("param_b",[3,4])
    def test_2(self,param):
        pass

Now it uses parameters like this:

test_tmp.py::TestTest::test_1[1][3]
test_tmp.py::TestTest::test_1[1][4]
test_tmp.py::TestTest::test_1[2][3]
test_tmp.py::TestTest::test_1[2][4]

test_tmp.py::TestTest::test_2[1][3]
test_tmp.py::TestTest::test_2[1][4]
test_tmp.py::TestTest::test_2[2][3]
test_tmp.py::TestTest::test_2[2][4]

And I would like it to use the parameters like this:

test_tmp.py::TestTest::test_1[1][3]
test_tmp.py::TestTest::test_1[1][4]
test_tmp.py::TestTest::test_2[1][3]
test_tmp.py::TestTest::test_2[1][4]

test_tmp.py::TestTest::test_1[2][3]
test_tmp.py::TestTest::test_1[2][4]
test_tmp.py::TestTest::test_2[2][3]
test_tmp.py::TestTest::test_2[2][4]

Is there any way to achieve this?

rjs325
  • 1
  • Could you please explain why do you need the tests to run in this order? They should be independent hence the order should not be important. – Yevhen Kuzmovych Apr 08 '21 at 11:57
  • 1
    Also, does this answer your question? [maintaining order of test execution when parametrizing tests in test class](https://stackoverflow.com/questions/31957216/maintaining-order-of-test-execution-when-parametrizing-tests-in-test-class) – Yevhen Kuzmovych Apr 08 '21 at 11:58
  • Hi, unfortunately I need a different aproach to the one You provided in the link. The reason is, that the tests have a specific order and must go one after another. E.g. param_b are subsystems, that must do all of the tests in order, before changing the param_a and doing all tests in order again. – rjs325 Apr 08 '21 at 12:15
  • 1
    As I said, good unit tests should be independent. If something has an order, it should be a part of a single unit test. – Yevhen Kuzmovych Apr 08 '21 at 13:16
  • I understand, however this is not a unit test, but an integration/functional test – rjs325 Apr 08 '21 at 13:19

0 Answers0