Skip to main content

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, and aiohttp without 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


Download files

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

Source Distribution

pytest_synapse-1.0.1.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

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

pytest_synapse-1.0.1-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

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

Hashes for pytest_synapse-1.0.1.tar.gz
Algorithm Hash digest
SHA256 624df01e4ef7e087d8e5bae418b0530610d90d26def314d1099429b084dae4f2
MD5 0c45b1d3439fcd7f595643e3617c20c4
BLAKE2b-256 cb07364c3154f860bf59f52ddf6b95c2236fc8dfea5a7fa5e874c7fcd338a09e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_synapse-1.0.1.tar.gz:

Publisher: release.yml on Jacky97s/pytest-synapse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pytest_synapse-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a30edbdd39e3f58e93ae2b608a02e596cfcec0cd5d3b30f3614b8246be56723e
MD5 7d1aee11ec5d53d1c006ba3de8de320a
BLAKE2b-256 4f7fddeaa58de213e3a524a8bb537f2d40e543a457ea08bc06296915b17993af

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_synapse-1.0.1-py3-none-any.whl:

Publisher: release.yml on Jacky97s/pytest-synapse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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