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 == codeNewman 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.xmlGotchas
- 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
How to Run REST API Tests With pytest and requests in CIRun integration tests against a REST API in GitHub Actions using pytest and the requests library, with a JUni…
How to Run Postman Collections With Newman in CIRun a Postman collection in GitHub Actions with the Newman CLI, passing an environment file and emitting a JU…
How to Publish an API Test JUnit Report in CIEmit a JUnit XML report from any API test runner in GitHub Actions and publish it, so passed and failed reque…