Metadata-Version: 2.4
Name: pytest-jsonschema
Version: 1.0.0
Summary: A pytest plugin to perform JSONSchema validations
Project-URL: Homepage, https://github.com/collective/pytest-jsonschema
Project-URL: PyPI, https://pypi.org/project/pytest-jsonschema
Project-URL: Source, https://github.com/collective/pytest-jsonschema
Project-URL: Tracker, https://github.com/collective/pytest-jsonschema/issues
Author-email: Érico Andrei <ericof@plone.org>
Maintainer-email: Érico Andrei <ericof@plone.org>
License: 
        The MIT License (MIT)
        
        Copyright (c) 2024 Érico Andrei
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
License-File: LICENSE
Keywords: pytest,testing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: jsonschema
Requires-Dist: pytest>=6.2.0
Requires-Dist: ruamel-yaml
Requires-Dist: tomli==2.0.1; python_version <= '3.11'
Description-Content-Type: text/markdown

<h1 align="center">pytest-jsonschema</h1>

<div align="center">

[![PyPI](https://img.shields.io/pypi/v/pytest-jsonschema)](https://pypi.org/project/pytest-jsonschema/)
[![Python Version](https://img.shields.io/pypi/pyversions/pytest-jsonschema)](https://pypi.org/project/pytest-jsonschema/)
[![Wheel](https://img.shields.io/pypi/wheel/pytest-jsonschema)](https://pypi.org/project/pytest-jsonschema/)
[![License](https://img.shields.io/pypi/l/pytest-jsonschema)](https://pypi.org/project/pytest-jsonschema/)
[![Status](https://img.shields.io/pypi/status/pytest-jsonschema)](https://pypi.org/project/pytest-jsonschema/)
[![Tests / QA](https://github.com/collective/pytest-jsonschema/actions/workflows/ci.yml/badge.svg)](https://github.com/collective/pytest-jsonschema/actions/workflows/ci.yml)
[![Contributors](https://img.shields.io/github/contributors/collective/pytest-jsonschema)](https://github.com/collective/pytest-jsonschema/graphs/contributors)
[![Stars](https://img.shields.io/github/stars/collective/pytest-jsonschema?style=social)](https://github.com/collective/pytest-jsonschema/stargazers)

</div>

**pytest-jsonschema** is a plugin for [pytest](https://docs.pytest.org) 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:

```bash
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:

```python
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:

```python
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:

```python
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:

```bash
git clone git@github.com:collective/pytest-jsonschema.git
```

2. Install the package for development:

```bash
make install
```

3. Format the codebase:

```bash
make format
```

4. Run tests:
- To run all tests:
  ```bash
  uv run pytest
  ```
- To stop on the first error and open a pdb session:
  ```
  uv run pytest -x --pdb
  ```

Testing is conducted using [`pytest`](https://docs.pytest.org/en/stable/).

## License 📜

**pytest-jsonschema** is licensed under the [MIT License](./LICENSE).
