I have test case which I want to execute with multiple test data. Using CSV to provide data and use same data for parameterization. But when I execute parameterize test case, the sequence of test data is get shuffled. I need to execute test case in same sequence as given in CSV. Even for normal parameterization I am facing same issue it does not execute test in same order as given.
CSV_FILE_NAME = "CSV file path"
CSV_FILE_PATH = os.path.join(os.getcwd(), CSV_FILE_NAME)
def load_tests_from_csv(file_path):
with open(file_path, newline='', encoding='utf-8-sig') as csvfile:
reader = csv.DictReader(csvfile)
return list(reader)
test_data = load_tests_from_csv(CSV_FILE_NAME)
class TestClassTest:
@pytest.fixture(params=test_data, scope="class")
def test_data(self, request):
return request.param
def test_generated(self, test_data):
assert True
# Use test_data in your test logic
print(f"Running test with row data: {test_data}")
Does any one have idea how to execute this test cases in same sequence as given in CSV? Also, I can not use ordering for each test case as I have more than 50 test scenarios in CSV.
I have tried with providing scope to the fixture. Also using pytest hook pytest_generate_tests but did not work.
should use
@pytest.mark.parametrize
csv file like: enter image description here