Files
pydantic/docs/hypothesis_plugin.md
T
Arseny Boykov c24d33e5f1 Generate docs exampels for Python 3.10 and above (#4339)
* Generate docs exampels for Python 3.10 and above

Code quality is not great and main intent here is to show the result.

* Fix docs build on 3.9

* Build docs on 3.10

* What's Python 3.1?

* Create temp dir if not exists

* Refactor and improve imlementetion

* Keep runtime typing in examples

* Revert unrelated formatting changes

* Add changes file

* Allow specifying requirements in examples

* Pin autoflake and pyupgrade

* Add docs/build to Makefile lint/format/mypy

* ignore_missing_imports for ansi2html and devtools

* Add .tmp-projections to .gitignore

* Remove dont-upgrade now when Pattern is supported

* Update postponed evaluation examples

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-14 17:21:53 +01:00

1.6 KiB

Hypothesis is the Python library for property-based testing. Hypothesis can infer how to construct type-annotated classes, and supports builtin types, many standard library types, and generic types from the typing and typing_extensions modules by default.

From Pydantic v1.8 and Hypothesis v5.29.0, Hypothesis will automatically load support for custom types like PaymentCardNumber and PositiveFloat, so that the st.builds() and st.from_type() strategies support them without any user configuration.

!!! warning Please note, while the plugin supports these types, hypothesis will(currently) generate values outside of given args for the constrained function types.

Example tests

{!.tmp_examples/hypothesis_property_based_test.md!}

Use with JSON Schemas

To test client-side code, you can use Model.schema() with the hypothesis-jsonschema package to generate arbitrary JSON instances matching the schema. For web API testing, Schemathesis provides a higher-level wrapper and can detect both errors and security vulnerabilities.