Skip to content Skip to sidebar Skip to footer

Pytest Parameters Execution Order For Repeated Test Seems To Be Wrong

I am trying to run a test repeatedly which is a paramertrized. it doesn't seem to follow the order while executing test. I tried using pytest-repeat and pytest.mark.parametrize but

Solution 1:

Finally i found a way to do it. Instead of having scenarios in conftest i moved it in a test and then using pytest.mark.parametrize. pytest groups the params instead of executing as a list one by one. anyway the way i achieved is as follows : Remember the count order should be close to the test method

test_param.py

scenarios = [('first', {'attribute': 'value'}), ('second', {'attribute': 'value'})]

@pytest.mark.parametrize("test_id,scenario",scenarios)@pytest.mark.parametrize("count",range(3)) #Remember the order , if you move it first then it will not run it the order i desired i-e first,second,first seconddeftest_scenarios(test_id,scenario,count):
   assert scenario["attribute"] == "value"

The output will be

test_scenario[0-first-scenario0]
test_scenario[0-second-scenario1]
test_scenario[1-first-scenario0]
test_scenario[1-second-scenario1]
test_scenario[2-first-scenario0]
test_scenario[2-second-scenario1]

Hope this helps

Post a Comment for "Pytest Parameters Execution Order For Repeated Test Seems To Be Wrong"