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.1.0.tar.gz (53.1 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.1.0-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_synapse-1.1.0.tar.gz.

File metadata

  • Download URL: pytest_synapse-1.1.0.tar.gz
  • Upload date:
  • Size: 53.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 4e6e2d7a987ec531a32c1d11b921b2b678795e402f528946dab1279b5cc54047
MD5 4204a78e7070d25306b226d56baf8ec3
BLAKE2b-256 d836d3cc0f033aa7dcbc3fad5bcf84be71539e195b7a74e3016dc4a00ef0a730

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_synapse-1.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_synapse-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92a9822fd89e1ad3cd89ddc38ccd9dedb22ac4cad2b703e0b14c85bdf493d1e6
MD5 715508ab6ffe8b8119473993f14d5998
BLAKE2b-256 8b406b4a705beaf65d6432b218e57d7e0f7e0f3bed62744a1c1bab072b20da23

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_synapse-1.1.0-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