跳转到主要内容

pytest插件,用于执行JSONSchema验证

项目描述

pytest-jsonschema

PyPI Python Version Wheel License Status Tests Linters Code Style Contributors Stars

pytest-jsonschema 是一个为 pytest 设计的插件,旨在简化在测试套件中执行JSON Schema验证。此工具允许您验证JSON文件、字符串和Python对象,以确保数据符合预期的格式。

安装

使用pip从PyPI安装 pytest-jsonschema

pip install pytest-jsonschema

功能 & 使用

该包引入了三个pytest fixture来验证JSON数据

schema_validate_file

验证位于您的测试套件目录中的JSON文件

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

验证JSON字符串

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

验证表示JSON数据的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")

需求

  • pytest >= 6.2.0

贡献

要为 pytest-jsonschema 贡献,请按照以下步骤操作

  1. 克隆仓库
git clone git@github.com:collective/pytest-jsonschema.git
  1. 为开发安装包
make install
  1. 格式化代码库
make format
  1. 运行测试
  • 要运行所有测试
    make test
    
  • 在第一个错误处停止并打开pdb会话
    make debug-test
    

测试使用 pytesttox 进行。

许可证 📜

pytest-jsonschema 采用 MIT许可证 许可。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

pytest-jsonschema-1.0.0a2.tar.gz (88.2 kB 查看哈希值)

上传时间

构建分发

pytest_jsonschema-1.0.0a2-py3-none-any.whl (84.3 kB 查看哈希值)

上传时间 Python 3

由以下机构支持