Skip to main content

A pytest plugin to perform JSONSchema validations

Project description

pytest-jsonschema

PyPI Python Version Wheel License Status Tests Linters Code Style 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 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:
    make test
    
  • To stop on the first error and open a pdb session:
    make debug-test
    

Testing is conducted using pytest and tox.

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.0a2.tar.gz (88.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pytest-jsonschema-1.0.0a2.tar.gz.

File metadata

  • Download URL: pytest-jsonschema-1.0.0a2.tar.gz
  • Upload date:
  • Size: 88.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.7

File hashes

Hashes for pytest-jsonschema-1.0.0a2.tar.gz
Algorithm Hash digest
SHA256 9d6e595921fc4bc42fdcb3d255c7fbad03d425ab85612ad7c6d86e4fca29f3bb
MD5 0a5669d581c5fe53523b6a4bd5668647
BLAKE2b-256 156629cb1ab714d33473415aa6232db1468b89c0623732beb26589bc6d75603e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_jsonschema-1.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 0140f0973b137d18a0e0527ba5be4bf811fad640388289d7d8a511a613b32bc3
MD5 e08bf8ce0cb3615bbb11925ff689162c
BLAKE2b-256 cafe1b417a16d396c6b4272f8d3c853e840befc429a54e3ea80316c50d2f93ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page