59 / 80 · 12 Programming for QA · Regex and Parsing← prev⊞ allnext →☰ Read as one page
7.8CSV Parsing for Test Data
import csv
# Read test data from CSV
with open("test_cases.csv") as f:
reader = csv.DictReader(f)
test_data = list(reader)
# [{"email": "test1@test.com", "expected_status": "200"}, ...]
# Use in parametrized tests
@pytest.mark.parametrize("row", test_data)
def test_from_csv(api_client, row):
response = api_client.post("/auth/login", json={
"email": row["email"], "password": row["password"]
})
assert response.status_code == int(row["expected_status"])