pytest-schema
👍 Validate return values against a schema-like object in testing
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-schemauv
uv add pytest-schemapoetry
poetry add pytest-schemaInstalling 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
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
schemaValidates Python data structures (dicts, lists,…
permissive · top 1,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
yamaleYamale validates YAML files against a schema…
permissive · top 5,000 on PyPI
pandas-schemaValidates pandas DataFrames against…
permissive · top 15,000 on PyPI
pytest-unorderedProvides a pytest assertion helper to compare…
permissive · top 5,000 on PyPI
django-pydantic-fieldProvides type-safe Pydantic model schemas for…
permissive · top 5,000 on PyPI
fastjsonschemaValidates JSON data against JSON Schema…
permissive · top 1,000 on PyPI
check-jsonschemaA command-line tool and pre-commit hook that…
permissive · top 5,000 on PyPI
magicattrProvides nested attribute access and…
permissive · top 5,000 on PyPI
json-schema-to-pydanticAutomatically generates Pydantic v2 models from…
permissive · top 5,000 on PyPI