Skip to main content

A pytest plugin to perform JSONSchema validations

Project description

pytest-jsonschema

PyPI Python Version Wheel License Status Tests / QA Contributors Stars

pytest-jsonschema is a plugin for pytest designed to facilitate JSON Schema validations within your test suites. This tool enables you to validate JSON files, strings, and Python objects against predefined JSON Schemas, ensuring your data adheres to expected formats.

Installation

Install pytest-jsonschema using pip / uv from PyPI:

pip install pytest-jsonschema

Features & Usage

The package introduces three pytest fixtures for validating JSON data:

schema_validate_file

Validates a JSON file located in your test suite directory:

from pathlib import Path

def test_package_json_is_valid(schema_validate_file):
    path = Path("package.json")
    assert schema_validate_file(path=path, schema_name="package")

schema_validate_string

Validates a JSON string:

from pathlib import Path

def test_package_json_is_valid(schema_validate_string):
    data = Path("package.json").read_text()
    assert schema_validate_string(data=data, schema_name="package", file_type="json")

schema_validate

Validates a Python dictionary representing JSON data:

import json
from pathlib import Path

def test_package_json_is_valid(schema_validate):
    data = json.loads(Path("package.json").read_text())
    assert schema_validate(data=data, schema_name="package")

Requirements

  • pytest >= 6.2.0

Contributing

To contribute to pytest-jsonschema, please follow these steps:

  1. Clone the repository:
git clone git@github.com:collective/pytest-jsonschema.git
  1. Install the package for development:
make install
  1. Format the codebase:
make format
  1. Run tests:
  • To run all tests:
    uv run pytest
    
  • To stop on the first error and open a pdb session:
    uv run pytest -x --pdb
    

Testing is conducted using pytest.

License 📜

pytest-jsonschema is licensed under the MIT 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

pytest_jsonschema-1.0.0.tar.gz (168.9 kB view details)

Uploaded Source

Built Distribution

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

pytest_jsonschema-1.0.0-py3-none-any.whl (111.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_jsonschema-1.0.0.tar.gz.

File metadata

  • Download URL: pytest_jsonschema-1.0.0.tar.gz
  • Upload date:
  • Size: 168.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for pytest_jsonschema-1.0.0.tar.gz
Algorithm Hash digest
SHA256 65af57cb3acd1d8e897b8e73dfd408d07f5aa90bab55126c9f9fb77480be627b
MD5 57e824d6e3e31eed295fa95cf020e6d1
BLAKE2b-256 d92eced4e814c7b685dd441fd57f6d79d516b5931abce8b25c9d5cf6f8769aa3

See more details on using hashes here.

File details

Details for the file pytest_jsonschema-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_jsonschema-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c47a18983556df5fa25c8094ea90bb4506455c846d7209eee6b9142538d253e
MD5 b05f1cceb1916bbfb1da4cf362d45c06
BLAKE2b-256 e6778726adee08a43955c99f5e8733362c5a131b012eab59bb8029020fe9621a

See more details on using hashes here.

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