skillfed

pytest-schema

👍 Validate return values against a schema-like object in testing

pytest-schema v0.1.2 113.4K downloads/30d#12,342 on PyPI9
Permissive license MIT DORMANT released

What it is and what it does

pytest-schema is a pytest plugin that wraps the schema library to validate Python data structures—typically API responses, config objects, or parsed JSON—against declarative schema definitions in test assertions. It provides functions like schema(), exact_schema(), and like_schema() that compare actual data against a template defining expected types, nested structures, optional fields, and custom validation rules (regex, enums, lambdas). When data matches the schema, the assertion passes; when it doesn't, a SchemaError is raised with details about the mismatch.

The package is designed for testing REST endpoints, webhooks, or any code that returns structured data. You define a schema once—a plain Python dict with types and validators—then reuse it across multiple tests. It handles optional fields, nested objects, lists, and custom predicates, making it useful for regression testing API contracts or validating config file parsing without writing repetitive type checks.

Use it for:

  • Validate JSON responses from REST API endpoints match expected structure and types in integration tests.
  • Test that config file parsing produces the correct nested dict/list structure with proper type conversions.
  • Ensure backwards compatibility by checking that new API versions still satisfy older schema constraints.
  • Validate webhook payloads or event data conform to a contract before processing in business logic.
  • Check that data transformations (e.g., ORM queries, ETL pipelines) produce correctly typed and shaped output.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Validates function return values and API responses against schema definitions in pytest tests, using the schema library to check data structure, types, and constraints.

Yes, if you need lightweight schema validation in pytest tests and don't require active maintenance. The package is stable and low-friction to install, but its dormant status (910 days since last release) means it won't receive updates for new pytest or Python versions. Use it for straightforward response validation; consider alternatives if you need ongoing support or complex JSON Schema features.

Install

pytest-schema on PyPI

pip

pip install pytest-schema

uv

uv add pytest-schema

poetry

poetry add pytest-schema

Installing pytest-schema

Before you install

Low friction install with only two runtime dependencies (pytest and schema). Dormant maintenance status—last release was 910 days ago with no recent commits, though the repository is not archived and the package is marked Production/Stable.

License in practice

MIT license permits use in proprietary and open-source projects with minimal restriction; you must include a copy of the license and copyright notice.

Quickstart

pip install pytest-schema

from pytest_schema import schema

article_schema = {"id": int, "title": str, "completed": bool}

def test_endpoint(test_client):
    response = test_client.get("/api/article/1")
    assert schema(article_schema) == response

Verify before relying

  • Whether the schema library's validation rules and error messages are sufficient for your test reporting needs.
  • Current compatibility with modern pytest versions and whether dormant status affects future pytest updates.

Package facts

License MIT (permissive)
Python support supports the current Python release (!=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*)
Install friction low — pure-Python wheel
Runtime dependencies 2 — pytest, schema
Maintenance dormant — 910 days since the last release
Last repo commit
First released
Downloads 113,396/month — #12,342 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_schema-0.1.2-py3-none-any.whl

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

pytest response validationschema validation testingapi response schema checkdata structure validation pytestjson schema testingtype checking test assertionsendpoint response validation
api-testingschema-validation

More Testing packages

pluggy

Pluggy provides a plugin system that lets you…

permissive · top 100 on PyPI

pytest

pytest is a testing framework that lets you…

permissive · top 100 on PyPI

virtualenv

virtualenv creates isolated Python environments…

permissive · top 100 on PyPI

coverage

Coverage.py measures which lines of Python code…

permissive · top 1,000 on PyPI

pytest-asyncio

pytest-asyncio is a pytest plugin that enables…

permissive · top 1,000 on PyPI

pytest-json-ctrf

A pytest plugin that generates test reports in…

permissive · top 1,000 on PyPI

schema

Validates Python data structures (dicts, lists,…

permissive · top 1,000 on PyPI

pytest-responses

Automatically mocks HTTP requests across your…

permissive · top 15,000 on PyPI

yamale

Yamale validates YAML files against a schema…

permissive · top 5,000 on PyPI

pandas-schema

Validates pandas DataFrames against…

permissive · top 15,000 on PyPI

pytest-unordered

Provides a pytest assertion helper to compare…

permissive · top 5,000 on PyPI

django-pydantic-field

Provides type-safe Pydantic model schemas for…

permissive · top 5,000 on PyPI

fastjsonschema

Validates JSON data against JSON Schema…

permissive · top 1,000 on PyPI

check-jsonschema

A command-line tool and pre-commit hook that…

permissive · top 5,000 on PyPI

magicattr

Provides nested attribute access and…

permissive · top 5,000 on PyPI

json-schema-to-pydantic

Automatically generates Pydantic v2 models from…

permissive · top 5,000 on PyPI