A tool to convert Postman collections to pytest test files
Project description
Postman to Pytest Converter
A Python tool that converts Postman collections to pytest test files, making it easier to integrate API tests into your Python testing workflow.
Features
- Converts Postman collections to pytest test files
- Maintains folder structure from Postman collections
- Generates test classes and methods
- Handles various HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Supports request headers, query parameters, and body data
- Generates conftest.py with common fixtures
- Creates requirements.txt with necessary dependencies
Installation
pip install postman-to-pytest
Usage
Command Line
postman-to-pytest path/to/postman_collection.json --output pytest_tests
Python Code
from postman_to_pytest import convert_postman_to_pytest
convert_postman_to_pytest(
collection_path="path/to/postman_collection.json",
output_dir="pytest_tests"
)
Generated Files Structure
The tool generates the following files:
pytest_tests/
├── conftest.py # Common fixtures
├── requirements.txt # Package dependencies
└── test_*_api.py # Test files for each Postman folder
Configuration
Environment Variables
Create a .env file in your project root:
API_BASE_URL=http://your-api-url
JWT_SECRET=your-jwt-secret
ORG_TOKEN=your-org-token
Fixtures
The generated conftest.py includes the following fixtures:
base_url: Base URL for API requestsjwt_token: JWT token for authenticationheaders: Common request headersorg_token: Organization token
Development
- Clone the repository:
git clone https://github.com/yourusername/postman-to-pytest.git
cd postman-to-pytest
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 postman_to_pytest-1.0.0.tar.gz.
File metadata
- Download URL: postman_to_pytest-1.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60404f5f6f514ff23823b09c762271340398ef36129b3709ade2cb29fb16a039
|
|
| MD5 |
1eeb89a1742ad75b90744b3260ac4b7b
|
|
| BLAKE2b-256 |
93db4f79d7d460804cc49f7d77f59352ae97ddf0144e9175f93d316880c1c78f
|
File details
Details for the file postman_to_pytest-1.0.0-py3-none-any.whl.
File metadata
- Download URL: postman_to_pytest-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3979e3fbe5ee071fd99128de02ff4a3daf9f89911ae66f0b4543242057dca495
|
|
| MD5 |
c4d51539b89c3ecd9864845607dd8d3e
|
|
| BLAKE2b-256 |
9d65bf0fef0d1f09e868aaed4eac6edebbb72ce78ffd630fbf54bc75a1c1534d
|