Convert Postman Collection v2.1 JSON files into executable pytest test suites
Project description
postman2pytest
Convert a Postman Collection v2.1 JSON file into a ready-to-run pytest test suite — in one command.
postman2pytest --collection my_api.json --out tests/test_api.py
BASE_URL=https://api.example.com pytest tests/test_api.py -v
Why
Postman collections document your API. postman2pytest turns that documentation into executable regression tests that run in CI — no manual rewriting, no drift.
Install
pip install postman2pytest
Or from source:
git clone https://github.com/golikovichev/postman2pytest
cd postman2pytest
pip install -e .
Usage
postman2pytest \
--collection data/my_api.postman_collection.json \
--out generated_tests/test_api.py
Then run the generated tests:
BASE_URL=https://staging.example.com pytest generated_tests/test_api.py -v
Options
| Flag | Required | Description |
|---|---|---|
--collection |
✅ | Path to Postman Collection v2.1 JSON |
--out |
✅ | Output path for generated pytest file |
--base-url |
❌ | Tip printed after generation (does not override env var) |
How It Works
- Parse — reads the Postman Collection JSON, flattens nested folders into a flat request list
- Extract — captures method, URL, headers, body, and expected status from
pm.response.to.have.status()test scripts - Generate — renders a Jinja2 template into a
.pyfile with onedef test_*()per request
Variable substitution
Postman variables {{base_url}} become ENV_base_url in the URL, resolved at runtime via the BASE_URL environment variable.
Generated output example
Given a Postman request GET {{base_url}}/api/v1/users with a test asserting status 200, the output is:
def test_get_users():
"""GET ENV_base_url/api/v1/users"""
url = f"{BASE_URL}/api/v1/users"
headers = {}
response = requests.get(url, headers=headers)
assert response.status_code == 200, (
f"Expected 200, got {response.status_code}: {response.text[:200]}"
)
Supported features
- ✅ Postman Collection v2.1 (v2.0 accepted with a warning)
- ✅ Nested folders → flattened with folder prefix in test name
- ✅ GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
- ✅ Request headers (disabled headers excluded)
- ✅ Raw JSON body
- ✅ Expected status from
pm.response.to.have.status(N)test scripts - ✅ Falls back to 200 when no status assertion found
- ✅ Malformed items skipped with a warning — rest of collection still generated
Running tests
pip install pytest
pytest tests/ -v
Contributing
See CONTRIBUTING.md.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postman2pytest-1.0.0.tar.gz.
File metadata
- Download URL: postman2pytest-1.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2237f134ef36098231e7e439b54a3ce139b3970179b0ab6a40a29f8cb1b9f3f6
|
|
| MD5 |
6a010f8796f2b01a3938386732127397
|
|
| BLAKE2b-256 |
dd214773bfef489c180638ea75e19a805926fe59ad413b41d3ef93bbabf00bff
|
File details
Details for the file postman2pytest-1.0.0-py3-none-any.whl.
File metadata
- Download URL: postman2pytest-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c40754c19a5eb5420ce786a48a61e7904ed031c4a640fc1392f48954bdcefa
|
|
| MD5 |
7c4fa096a3e4f5badf0381597e57cc6e
|
|
| BLAKE2b-256 |
5bd97900caff8b2616c4150c86c7cb5f5c2f84eb2b9859e5fcaa8bf19e105105
|