Skip to content Skip to sidebar Skip to footer

Maintaining Order Of Test Execution When Parametrizing Tests In Test Class

I am trying to parametrize my tests like below @pytest.mark.parametrize('a,b', test_data) class TestClass(): def test_A(self,a,b): # Some Code .. pass def t

Solution 1:

I was finally able to acheive this using pytest_generate_tests hook.

defpytest_generate_tests(metafunc):
    argvalues = []
    for data in metafunc.cls.data:
        items = data.items()
        argnames = [x[0] for x in items]
        argvalues.append(([x[1] for x in items]))
    metafunc.parametrize(argnames, argvalues, scope="class"classTestClass:
    data = [{'attr_1': 'val_1_1', 'attr_2': 'val_1_2'}, {'attr_1': 'val_2_1', 'attr_2': 'val_2_2'}]

    deftest_A(self, attr_1, attr_2)
    ...

    deftest_B(self, attr_1, attr_2)
    ...

    deftest_B(self, attr_1, attr_2)
    ...

https://pytest.org/latest/example/parametrize.html

Post a Comment for "Maintaining Order Of Test Execution When Parametrizing Tests In Test Class"