Skip to content
Latchkey

How to Run Data-Driven API Tests in CI

Data-driven tests feed a table of inputs into one test body, so coverage grows without new test code.

Use pytest.mark.parametrize for Python, or Newman's --iteration-data CSV to run a collection once per row of data.

pytest parametrize

tests/test_status.py
import pytest, requests, os
BASE = os.environ["API_BASE_URL"]

@pytest.mark.parametrize("code,path", [
    (200, "/health"),
    (404, "/missing"),
    (401, "/admin"),
])
def test_status(code, path):
    assert requests.get(f"{BASE}{path}", timeout=10).status_code == code

Newman iteration data

Terminal
newman run api.postman_collection.json \
  -e ci.postman_environment.json \
  --iteration-data users.csv \
  -r cli,junit --reporter-junit-export results/newman.xml

Gotchas

  • Keep each row independent so one failing case does not cascade into the others.
  • Name the parametrized case with ids= so a failure points at the exact input row.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →