Skip to main content

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 requests
  • jwt_token: JWT token for authentication
  • headers: Common request headers
  • org_token: Organization token

Development

  1. Clone the repository:
git clone https://github.com/yourusername/postman-to-pytest.git
cd postman-to-pytest
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
venv\Scripts\activate  # Windows
  1. Install development dependencies:
pip install -e ".[dev]"
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postman_to_pytest-1.0.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postman_to_pytest-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for postman_to_pytest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 60404f5f6f514ff23823b09c762271340398ef36129b3709ade2cb29fb16a039
MD5 1eeb89a1742ad75b90744b3260ac4b7b
BLAKE2b-256 93db4f79d7d460804cc49f7d77f59352ae97ddf0144e9175f93d316880c1c78f

See more details on using hashes here.

File details

Details for the file postman_to_pytest-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for postman_to_pytest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3979e3fbe5ee071fd99128de02ff4a3daf9f89911ae66f0b4543242057dca495
MD5 c4d51539b89c3ecd9864845607dd8d3e
BLAKE2b-256 9d65bf0fef0d1f09e868aaed4eac6edebbb72ce78ffd630fbf54bc75a1c1534d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page