Skip to main content

Fluent, chainable assertions for Python tests — HTTP, architecture, and database. Inspired by Laravel's elegant testing API.

Project description

pyssertive

Build Status Coverage

Fluent, chainable assertions for everything you test in Python. One vocabulary — from a single value to HTTP responses, JSON, HTML, MCP, and architecture. Inspired by Laravel's elegant testing API.

📚 Documentation

Full documentation lives at othercodes.github.io/pyssertive.

Features

  • One fluent vocabulary for any value, response, or contract under test
  • HTTP status code assertions (2xx, 3xx, 4xx, 5xx)
  • JSON response validation with path navigation, fragments, and JSON Schema contract testing
  • HTML content assertions with CSS-selector scoping
  • Template, context, session, cookie, and header assertions
  • Streaming response and file download assertions
  • Architecture assertions for import boundaries, layers, and bounded-context isolation
  • MCP (Model Context Protocol) assertions with MCP-native vocabulary
  • Debug helpers for test development

Requirements

  • Python 3.10+
  • Django 4.2, 5.2, or 6.0 (optional, only if using the Django adapter)
  • httpx 0.27+ (optional, only if using the httpx adapter for FastAPI/Starlette/FastMCP)

Installation

pip install pyssertive            # core
pip install pyssertive[django]    # with Django adapter
pip install pyssertive[httpx]     # with httpx adapter (FastAPI, Starlette, FastMCP)

Quickstart

from pyssertive import expect

# Generic values — one vocabulary for anything
expect(42).equals(42)
expect([1, 2, 3]).has_count(3).contains(2).does_not_contain(99)
expect("alice@example.com").is_instance_of(str).matches(r".+@.+")

# The same expect dispatches to specialized assertables
expect.json(payload).where("status", "active").missing("password")
expect.html(markup).see_text("Welcome back, Alice")
expect.arch("myapp.domain").should_only_depend_on(["stdlib", "myapp.domain"])

HTTP responses chain fluently from a test client:

import pytest
from pyssertive.adapters.django import FluentHttpAssertClient


@pytest.fixture
def client():
    from django.test import Client
    return FluentHttpAssertClient(Client())


@pytest.mark.django_db
def test_user_api(client):
    client.get("/api/users/")\
        .assert_ok()\
        .assert_json_path("count", 10)\
        .assert_header("Content-Type", "application/json")

See the documentation for the full guides and API reference.

License

MIT — see 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

pyssertive-0.10.1.tar.gz (85.7 kB view details)

Uploaded Source

Built Distribution

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

pyssertive-0.10.1-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file pyssertive-0.10.1.tar.gz.

File metadata

  • Download URL: pyssertive-0.10.1.tar.gz
  • Upload date:
  • Size: 85.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyssertive-0.10.1.tar.gz
Algorithm Hash digest
SHA256 0205a4ba29b973f14af96da72cc8e2c980335d9cc05538dd53c5ee0d461cdf60
MD5 481414dd9a213a291b5f97a8e09b45ed
BLAKE2b-256 f01b894bebab12b3cd4ed3b7dd52951ab5c231fd0b6778f9b5db4eac378beace

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyssertive-0.10.1.tar.gz:

Publisher: release.yml on othercodes/pyssertive

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

File details

Details for the file pyssertive-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: pyssertive-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyssertive-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c91be562faa67476b7df7ce8e95b0691f287879e034ec8cde9d229c14733f15a
MD5 991a6bef5db38fec8af7226b9a836bb2
BLAKE2b-256 63665ab017588968486944cd51ef10f8635bc5edcb4ceadb39a25c76fad855f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyssertive-0.10.1-py3-none-any.whl:

Publisher: release.yml on othercodes/pyssertive

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