A pytest plugin for OpenAPI contract test coverage
Project description
pytest-synapse
A pytest plugin for measuring OpenAPI contract test coverage by transparently intercepting HTTP traffic during test execution.
Key Features
- Transparent Interception: Automatically captures HTTP requests/responses from
requests,httpx, andaiohttpwithout modifying test code - OpenAPI Coverage: Maps captured traffic to your OpenAPI 3.x specification
- Granular Metrics: Coverage for paths, HTTP methods, request bodies, response status codes, response schemas, and field-level constraints
- Risk Assessment: Identifies high-risk untested endpoints with detailed risk scoring
- Multiple Output Formats: CLI, JSON, CSV, and HTML reports
- CI/CD Integration: Fail thresholds, baseline comparison, JUnit XML output, GitHub PR comments
- Field & Constraint Coverage: Track coverage of required fields, enums, string patterns, numeric ranges, and more
Installation
pip install pytest-synapse
Quick Start
# Basic usage
pytest --openapi-spec=./openapi.yaml
# With HTML report including risk assessment
pytest --openapi-spec=./openapi.yaml --synapse-report=report.html --synapse-report-format=html
# With coverage threshold
pytest --openapi-spec=./openapi.yaml --synapse-fail-under=80
Coverage Output
==================================================
OpenAPI Coverage Report
==================================================
Paths: 3/5 (60.0%)
Operations: 5/8 (62.5%)
Request Bodies: 2/3 (66.7%)
Response Schemas: 7/12 (58.3%)
==================================================
API RISK ASSESSMENT
==================================================
RISK SUMMARY
------------------------------------------------------------
Total Endpoints: 8
High Risk: 2
Medium Risk: 3
Low Risk: 3
Risk Score: 45.0/100
CRITICAL GAPS (High-risk + Uncovered):
[!] DELETE /users/{id}
[!] POST /payments
CLI Options
| Option | Description |
|---|---|
--openapi-spec |
Path to OpenAPI spec file or URL |
--synapse-report |
Output path for coverage report |
--synapse-report-format |
Format: json, csv, html, cli_summary, cli_detailed |
--synapse-fail-under |
Fail if coverage below threshold |
--synapse-risk-report |
Include risk assessment in CLI output |
--synapse-risk-report-output |
Export risk report to JSON file |
--synapse-strict |
Fail on contract violations |
--synapse-debug |
Enable debug logging |
Configuration File
Create .synapse.yaml in your project root:
spec: ./openapi.yaml
thresholds:
operations: 80
paths: 90
ignore:
paths:
- /health
- /metrics
methods:
- OPTIONS
risk:
high_risk_paths:
- /api/v1/admin/*
- /api/v1/payments/*
high_risk_methods:
- DELETE
- POST
Supported HTTP Clients
| Client | Sync | Async |
|---|---|---|
| requests | Yes | N/A |
| httpx | Yes | Yes |
| aiohttp | N/A | Yes |
Documentation
License
MIT License
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 pytest_synapse-1.0.1.tar.gz.
File metadata
- Download URL: pytest_synapse-1.0.1.tar.gz
- Upload date:
- Size: 48.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624df01e4ef7e087d8e5bae418b0530610d90d26def314d1099429b084dae4f2
|
|
| MD5 |
0c45b1d3439fcd7f595643e3617c20c4
|
|
| BLAKE2b-256 |
cb07364c3154f860bf59f52ddf6b95c2236fc8dfea5a7fa5e874c7fcd338a09e
|
Provenance
The following attestation bundles were made for pytest_synapse-1.0.1.tar.gz:
Publisher:
release.yml on Jacky97s/pytest-synapse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_synapse-1.0.1.tar.gz -
Subject digest:
624df01e4ef7e087d8e5bae418b0530610d90d26def314d1099429b084dae4f2 - Sigstore transparency entry: 1790997938
- Sigstore integration time:
-
Permalink:
Jacky97s/pytest-synapse@fa23fe4a49620608d1531619b6c7b554a5711d2c -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Jacky97s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa23fe4a49620608d1531619b6c7b554a5711d2c -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_synapse-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pytest_synapse-1.0.1-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a30edbdd39e3f58e93ae2b608a02e596cfcec0cd5d3b30f3614b8246be56723e
|
|
| MD5 |
7d1aee11ec5d53d1c006ba3de8de320a
|
|
| BLAKE2b-256 |
4f7fddeaa58de213e3a524a8bb537f2d40e543a457ea08bc06296915b17993af
|
Provenance
The following attestation bundles were made for pytest_synapse-1.0.1-py3-none-any.whl:
Publisher:
release.yml on Jacky97s/pytest-synapse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_synapse-1.0.1-py3-none-any.whl -
Subject digest:
a30edbdd39e3f58e93ae2b608a02e596cfcec0cd5d3b30f3614b8246be56723e - Sigstore transparency entry: 1790998097
- Sigstore integration time:
-
Permalink:
Jacky97s/pytest-synapse@fa23fe4a49620608d1531619b6c7b554a5711d2c -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Jacky97s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa23fe4a49620608d1531619b6c7b554a5711d2c -
Trigger Event:
push
-
Statement type: