| Name | pytest-pydantic-schema-sync JSON |
| Version |
0.2.1
JSON |
| download |
| home_page | None |
| Summary | Pytest plugin to synchronise Pydantic model schemas with JSONSchema files |
| upload_time | 2024-08-29 00:32:14 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.10 |
| license | MIT |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# pytest-pydantic-schema-sync
`pytest-pydantic-schema-sync` is a pytest plugin that automates the process of saving JSON schemas for Pydantic
models during test execution. It builds upon the functionality provided by the `pydantic-schema-sync` package.
## Features
- Automatically syncs JSON schemas for Pydantic models during pytest execution
- Configurable schema storage location (package root or repository root)
- Easy setup using pytest markers and Enum-based configuration
## Installation
You can install `pytest-pydantic-schema-sync` using pip:
```
pip install pytest-pydantic-schema-sync
```
## Usage
Define an Enum class with your Pydantic model paths, marked with the `pydantic_schema_sync` marker:
```python
from pytest import mark
from enum import Enum
@mark.pydantic_schema_sync
class ModelSchemas(Enum):
user = "myapp.models.User"
product = "myapp.models.Product"
```
Running your pytest suite will generate tests for each of these, which fail if the sync is unsuccessful.
The plugin will automatically generate and sync JSON schemas for the specified models using `pydantic-schema-sync`.
## Configuration
You can configure the plugin behavior in your `pytest.ini` or `pyproject.toml` file:
```ini
[tool.pytest.ini_options]
pydantic_schema_sync = {schema_location = "package_root", schema_dir = "schemas", repo_flatten = false, mjs_kwargs = {}}
```
These are the defaults, but it demonstrates use of JSON to configure the plugin.
- `schema_location`: Where to store schema files. Options are "package_root" (default) or "repo_root".
- `repo_flatten`: If "repo_root" is chosen, then if this option is set to True (default: False)
all JSON files will be written to a single directory rather than in subfolders per-package.
- `schema_dir`: Name of the directory to store schema files under whichever schema location root. Default is "schemas".
- `mjs_kwargs`: Keyword arguments to pass to the Pydantic models' `model_json_schema()` method.
Default is `{}` (i.e. do not override any kwargs).
- A common kwarg you may wish to set is `by_alias` (default: True)
## How It Works
The plugin uses the `pydantic-schema-sync` package to generate JSON schemas for your Pydantic models.
It creates a separate test item for each model specified in your Enum, ensuring that schemas are synced
even if no other tests are run for those models.
## Example
Check out the [simple-plugin-demo](https://github.com/lmmx/pydantic-schema-sync/tree/master/packages/simple-plugin-demo)
for a working example of how to use this plugin.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-pydantic-schema-sync",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Louis Maddox <louismmx@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/fa/73/bc228ffd6a10ef71ba4c54744b0544966a5a1a8966a75e926f927635ddf7/pytest_pydantic_schema_sync-0.2.1.tar.gz",
"platform": null,
"description": "# pytest-pydantic-schema-sync\n\n`pytest-pydantic-schema-sync` is a pytest plugin that automates the process of saving JSON schemas for Pydantic\nmodels during test execution. It builds upon the functionality provided by the `pydantic-schema-sync` package.\n\n## Features\n\n- Automatically syncs JSON schemas for Pydantic models during pytest execution\n- Configurable schema storage location (package root or repository root)\n- Easy setup using pytest markers and Enum-based configuration\n\n## Installation\n\nYou can install `pytest-pydantic-schema-sync` using pip:\n\n```\npip install pytest-pydantic-schema-sync\n```\n\n## Usage\n\nDefine an Enum class with your Pydantic model paths, marked with the `pydantic_schema_sync` marker:\n\n```python\nfrom pytest import mark\nfrom enum import Enum\n\n@mark.pydantic_schema_sync\nclass ModelSchemas(Enum):\n user = \"myapp.models.User\"\n product = \"myapp.models.Product\"\n```\n\nRunning your pytest suite will generate tests for each of these, which fail if the sync is unsuccessful.\nThe plugin will automatically generate and sync JSON schemas for the specified models using `pydantic-schema-sync`.\n\n## Configuration\n\nYou can configure the plugin behavior in your `pytest.ini` or `pyproject.toml` file:\n\n```ini\n[tool.pytest.ini_options]\npydantic_schema_sync = {schema_location = \"package_root\", schema_dir = \"schemas\", repo_flatten = false, mjs_kwargs = {}}\n```\n\nThese are the defaults, but it demonstrates use of JSON to configure the plugin.\n\n- `schema_location`: Where to store schema files. Options are \"package_root\" (default) or \"repo_root\".\n - `repo_flatten`: If \"repo_root\" is chosen, then if this option is set to True (default: False)\n all JSON files will be written to a single directory rather than in subfolders per-package.\n- `schema_dir`: Name of the directory to store schema files under whichever schema location root. Default is \"schemas\".\n- `mjs_kwargs`: Keyword arguments to pass to the Pydantic models' `model_json_schema()` method.\n Default is `{}` (i.e. do not override any kwargs).\n - A common kwarg you may wish to set is `by_alias` (default: True)\n\n## How It Works\n\nThe plugin uses the `pydantic-schema-sync` package to generate JSON schemas for your Pydantic models.\nIt creates a separate test item for each model specified in your Enum, ensuring that schemas are synced\neven if no other tests are run for those models.\n\n## Example\n\nCheck out the [simple-plugin-demo](https://github.com/lmmx/pydantic-schema-sync/tree/master/packages/simple-plugin-demo)\nfor a working example of how to use this plugin.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pytest plugin to synchronise Pydantic model schemas with JSONSchema files",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/lmmx/pydantic-schema-sync/packages/pytest-pydantic-schema-sync",
"Repository": "https://github.com/lmmx/pydantic-schema-sync.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "08ee40ca93f016b6411ecba0d6e55f61e9ce71bda73924bc2ff623557f999c76",
"md5": "fff16eef5e740d3af34bca26b9d9b58d",
"sha256": "54b94be98c099f1efc2318c3971080c6b52ca363133027e9a59a5a0b14ea7cf1"
},
"downloads": -1,
"filename": "pytest_pydantic_schema_sync-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fff16eef5e740d3af34bca26b9d9b58d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5102,
"upload_time": "2024-08-29T00:32:13",
"upload_time_iso_8601": "2024-08-29T00:32:13.155164Z",
"url": "https://files.pythonhosted.org/packages/08/ee/40ca93f016b6411ecba0d6e55f61e9ce71bda73924bc2ff623557f999c76/pytest_pydantic_schema_sync-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fa73bc228ffd6a10ef71ba4c54744b0544966a5a1a8966a75e926f927635ddf7",
"md5": "9141d0e613b2311063e9d9d518180f72",
"sha256": "c10067dbcb08decc8b06f8efe40afe2d50310a2fc198c49fd4de1adb2afd4272"
},
"downloads": -1,
"filename": "pytest_pydantic_schema_sync-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "9141d0e613b2311063e9d9d518180f72",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 3704,
"upload_time": "2024-08-29T00:32:14",
"upload_time_iso_8601": "2024-08-29T00:32:14.134394Z",
"url": "https://files.pythonhosted.org/packages/fa/73/bc228ffd6a10ef71ba4c54744b0544966a5a1a8966a75e926f927635ddf7/pytest_pydantic_schema_sync-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-29 00:32:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lmmx",
"github_project": "pydantic-schema-sync",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pytest-pydantic-schema-sync"
}