I have 2 pyTest test cases that take a parameter. I want to run them in order with both params, instead of the first test running with all possible values, and then the 2nd test starting.
Consider the below test code:
import pytest
@pytest.mark.parametrize("param1", [("A"), ("B")])
class TestClassTests:
def test_01_test(self, param1):
...
def test_02_test(self, param1):
...
The execution order I am getting is:
- test_01_test -- (A)
- test_01_test -- (B)
- test_02_test -- (A)
- test_02_test -- (B)
I want the order to be:
- test_01_test -- (A)
- test_02_test -- (A)
- test_01_test -- (B)
- test_02_test -- (B)
Got answer from here: maintaining order of test execution when parametrizing tests in test class
Just needs a scope="class" in the parametrize decorator.