🔍 Pytest JsonSchema SnapShot (JSSS)
Plugin for pytest that automatically / manually generates JSON Schemas tests with validates data.
⭐ Star us on GitHub | 📚 Read the Docs | 🐛 Report Bug
✨ Features
- Automatic JSON Schema generation from data examples (using the
genschemalibrary). - Format detection: Automatic detection and validation of string formats (email, UUID, date, date-time, URI, IPv4).
- Enum inference: Short low-cardinality string fields are narrowed to
enumautomatically. - Schema post-processing: Repeated structures are extracted into
$defs/$refto keep generated schemas smaller and easier to review. - Schema storage and management.
- Validation of data against saved schemas.
- Schema update via
--schema-update(create new schemas, remove unused ones, update existing). - Support for both
asyncand synchronous functions. - Support for
Uniontypes and optional fields. - Built-in diff comparison of changes via jsonschema-diff.
Installation
pip install pytest-jsonschema-snapshot
Usage
- Use the
schemashotfixture in your tests
import pytest
from you_lib import API
from pytest_jsonschema_snapshot import SchemaShot
@pytest.mark.asyncio
async def test_something(schemashot: SchemaShot):
data = await API.get_data()
# There are data - need to validate through the schema
schemashot.assert_json_match(
data, # data for validation / convert to schema
"test_name" # name of the schema
)
schema = await API.get_schema()
# There is a schema (data is optional) - validate by what is
schemashot.assert_schema_match(
schema,
(API.get_schema, "test_name", 1), # == `API.get_schema.test_name.1` filename
data=data # data for validation (optional)
)
-
On first run, generate schemas with the
--schema-updateor--schema-reset(what is the difference? see the documentation) flagpytest --schema-update --save-original
--save-original: save the original data on which the validation was performed. Saving occurs when
--schema-updateor--schema-reset, if you run the schema update without this attribute, the old original data will be deleted without saving new ones. --jsss-ci-cd: CI mode is intended for automatic PR generation; it saves updates (like--schema-update) to__snapshots__/ci.cd/(--save-originalis compatible). -
On subsequent runs, tests will validate data against saved schemas
pytest
Generated schemas are refined by genschema before they are written:
format detection, enum inference for short low-cardinality strings, and post-processing that extracts repeated fragments into $defs/$ref.
-
Union Types: support multiple possible types for fields
-
Optional Fields: automatic detection of required and optional fields
-
Enum Narrowing: generated schemas can automatically emit
enumfor short string fields with a small set of observed values -
Reference Extraction: repeated object/array shapes can be factored into
$defsand reused via$ref -
Format Detection: automatic detection of string formats including:
Format Example JSON Schema Email user@example.com{"format": "email"}UUID 550e8400-e29b-41d4-a716-446655440000{"format": "uuid"}Date 2023-01-15{"format": "date"}Date-Time 2023-01-01T12:00:00Z{"format": "date-time"}URI https://example.com{"format": "uri"}IPv4 192.168.1.1{"format": "ipv4"} -
Cleanup: automatic removal of unused schemas when running in update mode
-
Schema Summary: colored terminal output showing created, updated, deleted and unused schemas
Advanced Usage? Check the docs!
Best Practices
- Commit schemas to version control: Schemas should be part of your repository
- Review schema changes: When schemas change, review the diffs carefully without
--schema-updateresets. - Clean up regularly: Use
--schema-updateperiodically to remove unused schemas - Descriptive names: Use clear, descriptive names for your schemas
# Fork the repo, then:
git clone https://github.com/Miskler/pytest-jsonschema-snapshot.git
cd jsonschema-diff
# Install
make reinstall
# Ensure everything works
make test
make lint
make type-check
# After code editing
make format
📄 License
MIT License - see LICENSE file for details.
Made with ❤️ for developers working with evolving JSON schemas
Metadata
Release files for pytest-jsonschema-snapshot 0.2.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_jsonschema_snapshot-0.2.9.tar.gz | 202.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_jsonschema_snapshot-0.2.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 220.7 kB
Release files / pytest_jsonschema_snapshot-0.2.9.tar.gz
| Download URL | pytest_jsonschema_snapshot-0.2.9.tar.gz |
|---|---|
| Size | 202.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f57480489baa9ec5eb1708d7b6847470a0136a918b0cac58256b994defedd75
|
|
BLAKE2b-256 checksum How to use checksums |
cad568d18dfb82b3af7e4af327d57f5e560318778c1c083cad97dad5d93d4fb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 29, 2026.
Transparency logRelease files / pytest_jsonschema_snapshot-0.2.9-py3-none-any.whl
| Download URL | pytest_jsonschema_snapshot-0.2.9-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e00e34ea758fa2245dc8a65438b94c9208907a8e7f8bb2fd9e7fdf89d2fcb4a
|
|
BLAKE2b-256 checksum How to use checksums |
d9126bdff6a7d38f75fd9a667cc506ceb32a8f06f268597426978724686a7c9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 29, 2026.
Transparency log