Skip to main content

pytest-verifies

CI Python License Standards

Enterprise Requirements Traceability Plugin for Pytest.

pytest-verifies seamlessly links automated test suites to formal engineering requirements (such as ISO 26262, IEC 62304, DO-178C, and SOC2) and produces audit-ready Requirements Traceability Matrix (RTM) artefacts.


1. Core Philosophy & Key Features

  1. Standard Pytest Assertions Only: No custom assertion wrappers. Use native Python assert statements inside with verifies(...) or on functions decorated with @verifies(...). Pytest's AST assertion rewriting and rich diff diagnostics are 100% preserved.
  2. Unified API: A single callable, verifies, functions interchangeably as a function/class decorator, context manager, and parametrised mark (pytest.param(..., marks=verifies(...))).
  3. Soft Assertions & Objective Evidence: Support for non-fatal assertions (soft=True or --verifies-soft) enables tests to evaluate multiple requirements sequentially before reporting consolidated failures. Dynamically attach objective runtime evidence (ctx.attach("telemetry", value) or ctx.record_evidence(dict)).
  4. pytest-xdist Concurrency Safe: Workers never write directly to shared report files or depend on inter-process locks. Verification records are serialised onto report.user_properties and transmitted to the controller node.
  5. Multi-Run Shard Consolidation: Modelled after coverage.py. Distinct test invocations across disparate execution environments or CI stages (e.g. unit, integration, system) write atomic .jsonl shards. The standalone pytest-verifies combine CLI merges shards against baseline requirement manifests.
  6. Multi-Format Artefact Generation: Generates structured JSON, tabular CSV, GitHub/GitLab step summary Markdown, and interactive single-file HTML5 reports with zero external runtime JavaScript or CSS dependencies.
  7. Strict Quality Gates: Enforce requirement coverage thresholds (--verifies-fail-under), disallow orphaned requirement IDs (--verifies-disallow-orphans), and fail pipelines when known defects or unverified requirements are detected.

2. Installation

Install using uv (recommended):

uv add pytest-verifies

Or using standard Python package managers:

pip install pytest-verifies

3. Quick Start & Python API

3.1 Decorator Usage

Decorate test functions or classes to associate them with one or more requirements:

from pytest_verifies import verifies


@verifies("REQ-DOG-001", "REQ-DOG-002", description="Dogs must be friendly and able to bark")
def test_dog_attributes():
    dog = {"name": "Buster", "species": "Canis familiaris", "barks": True}
    assert dog["barks"] is True

3.2 Single-Line Context Manager

Verify fine-grained inline statements while preserving full assertion diffs:

from pytest_verifies import verifies


def test_cat_purring():
    cat = {"name": "Whiskers", "purring": True}
    with verifies("REQ-CAT-001"):
        assert cat["purring"] is True

3.3 Soft Assertions & Objective Evidence

Evaluate multiple requirements within a single test execution without early termination on the first failure:

from pytest_verifies import verifies


def test_dog_health_and_energy():
    dog = {"name": "Buster", "happy": True, "tail_wags_per_min": 120}

    # Block 1: Soft assertion with static objective evidence
    with verifies(
        "REQ-DOG-002",
        description="Dogs must wag their tails when happy",
        soft=True,
        evidence={"dog_name": dog["name"], "happy": dog["happy"]},
    ):
        assert dog["happy"] is True

    # Block 2: Execution continues even if Block 1 fails
    with verifies("REQ-DOG-003", soft=True) as ctx:
        ctx.attach("tail_wags_per_min", dog["tail_wags_per_min"])
        ctx.record_evidence({"breed": "Golden Retriever"})
        assert dog["tail_wags_per_min"] > 60

3.4 Parametrised Tests

Attach requirement tags to specific test parameters:

import pytest
from pytest_verifies import verifies


@pytest.mark.parametrize(
    "animal,sound",
    [
        pytest.param("dog", "woof", marks=verifies("REQ-DOG-001")),
        pytest.param("cat", "meow", marks=verifies("REQ-CAT-001")),
        pytest.param("puppy", "yip", marks=verifies("REQ-DOG-001")),
    ],
)
def test_pet_sounds(animal, sound):
    pet_sounds = {"dog": "woof", "cat": "meow", "puppy": "yip"}
    assert pet_sounds[animal] == sound

3.5 Test Procedure Steps & Action Steps

Test protocols often require tracking discrete step IDs (STEP-01, 1.1), including Action Steps (preparing state) and Verification Steps (checking requirements):

from pytest_verifies import step, verifies


def test_puppy_training_routine():
    # Action step: Prepare treat and call puppy
    with step("STEP-01", description="Fill treat pouch and call puppy"):
        puppy = {"name": "Buster", "tricks": []}

    # Verification step: Directly validates REQ-DOG-004
    with step("STEP-02", description="Verify puppy sits on command", verifies="REQ-DOG-004"):
        puppy["tricks"].append("sit")
        assert "sit" in puppy["tricks"]

    # Verification step with verifies(..., step=...)
    with verifies("REQ-DOG-002", step="STEP-03", description="Verify puppy wags tail after treat"):
        tail_wagging = True
        assert tail_wagging is True

4. Pytest Command-Line & Configuration Options

Option Ini Configuration Description
--req="PATTERN" — Comma-separated requirement IDs or glob patterns to filter tests (e.g. --req="REQ-DOG-*,REQ-CAT-001").
--verifies-out=DIR verifies_out = DIR Directory to output .jsonl execution shards.
--verifies-stage=NAME verifies_stage = NAME Stage label for execution shard (default: "default").
--verifies-baseline=PATH verifies_baseline = PATH Path to baseline requirement manifest (.json, .csv, .yaml).
--verifies-soft verifies_soft = true Enable soft verification mode globally across all verifies blocks.
--verifies-disallow-orphans — Fail collection/session if tests reference IDs not present in baseline.
--verifies-fail-under=NUM — Fail session if verified requirement coverage % is below threshold (0–100).
--verifies-json=PATH — Direct output file for structured JSON RTM report.
--verifies-csv=PATH — Direct output file for tabular CSV RTM report.
--verifies-md=PATH — Direct output file for Markdown summary report.
--verifies-html=PATH — Direct output file for interactive single-file HTML5 report.

5. Baseline Requirement Manifests

Baseline manifests declare formal specifications against which automated tests are verified. Baseline requirements need only an id and a requirement statement text (or description).

JSON Manifest (requirements.json)

{
  "requirements": [
    {
      "id": "REQ-DOG-001",
      "text": "Dogs must be able to bark"
    },
    {
      "id": "REQ-CAT-001",
      "text": "Cats must be able to purr when content"
    }
  ]
}

CSV Manifest (requirements.csv)

id,text
REQ-DOG-001,Dogs must be able to bark
REQ-CAT-001,Cats must be able to purr when content

YAML Manifest (requirements.yaml)

requirements:
  - id: REQ-DOG-001
    text: Dogs must be able to bark
  - id: REQ-CAT-001
    text: Cats must be able to purr when content

6. Multi-Run Shard Consolidation Workflow

In distributed CI pipelines, different test tiers (unit, integration, end-to-end) run in isolated containers. pytest-verifies enables merging these shards into a single consolidated matrix:

Step 1: Run Stage Test Suites

# Unit test tier
uv run pytest tests/unit --verifies-out=.verifies --verifies-stage=unit

# Integration test tier
uv run pytest tests/integration --verifies-out=.verifies --verifies-stage=integration

# End-to-end / System test tier
uv run pytest tests/system --verifies-out=.verifies --verifies-stage=system

Step 2: Combine Shards via CLI

uv run pytest-verifies combine .verifies/ \
  --baseline requirements.json \
  --disallow-orphans \
  --fail-under 100.0 \
  --json rtm.json \
  --csv rtm.csv \
  --md rtm.md \
  --html rtm.html

Quality Gate Exit Codes

  • 0: Success. All quality gates met (100% of tested requirements verified, coverage threshold met, no orphaned IDs).
  • 1: Quality gate failure. One or more requirements failed, orphaned IDs were detected, or verified requirement coverage is below --fail-under.

7. Reporting Artefacts

Interactive HTML5 Report

Self-contained, responsive, single-file HTML5 document with zero external network dependencies:

  • Metric Cards: Total Requirements, Pass %, Fail %, Partial %, Orphan Count.
  • Dynamic Filtering: Instant filtering by status (All, Pass, Partial, Fail, Orphans).
  • Live Search: Fast search by Requirement ID, title, test nodeid, or file location.
  • Diagnostic Expansion: Interactive <details> sections displaying execution trace, attached objective evidence, and failure tracebacks.

GitHub / GitLab Markdown Summary

Designed directly for $GITHUB_STEP_SUMMARY and merge request comments:

  • Summary Scorecard Table with clean status indicators (PASS, FAIL, PARTIAL, [ORPHAN]).
  • Requirements Traceability Table detailing stage coverage (when stages are configured) and verification tests.
  • Collapsible diagnostics with assertion tracebacks and formatted JSON evidence.

Tabular CSV Export

Standardised format for enterprise PLM / ALM tools (e.g. Jira, Jama, Polarion):

req_id,text,status,in_baseline,stages,tests,evidence,failure_messages

(The stages column is dynamically included only when execution stages are configured).


8. Standards Compliance

Standard Applicable Clauses How pytest-verifies Supports Compliance
ISO 26262 Part 6, Section 9 & 10 Provides bidirectional requirements-to-test traceability and verification evidence for ASIL A–D.
IEC 62304 Section 5.7 & 5.8 Establishes automated software verification records and RTM reports for Class A–C medical software.
DO-178C Section 6.4.4 Demonstrates verification of software requirements and records objective test execution results.
SOC2 / ISO 27001 CC7.1, CC7.4 Auditable proof that automated security controls and regression tests verify baseline control specifications.

9. Licence

Distributed under the terms of the MIT licence.

Metadata

Release files for pytest-verifies 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-verifies 1.1.1
File Size Uploaded Provenance
pytest_verifies-1.1.1.tar.gz 137.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-verifies 1.1.1
File Interpreter ABI Platform
pytest_verifies-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 175.3 kB

Release files / pytest_verifies-1.1.1.tar.gz

Download URL pytest_verifies-1.1.1.tar.gz
Size 137.7 kB
Tags Source
SHA-256 checksum
How to use checksums
247a6ed4c8ad0373114853bf884076410d975dbc4a2d4442dbacc5b1fc4e2762
BLAKE2b-256 checksum
How to use checksums
822af250c42405c124727e1b0865699b10b051426bf45f559a73b2540246388f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / pytest_verifies-1.1.1-py3-none-any.whl

Download URL pytest_verifies-1.1.1-py3-none-any.whl
Size 37.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fbd2c314a3faf782e92c7bbb78a4f6a9830686d1b88a36ee1925e4ed94dd081
BLAKE2b-256 checksum
How to use checksums
ee306a173129e3d7aadd777d93ecf930cae28c54cb8b0cf69e5ed3e3287db08f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for pytest-verifies 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_verifies-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page