* renaming .json -> .model_dump_json * renaming .dict -> .model_dump * renaming .__fields__ -> .model_fields * renaming .schema -> .model_json_schema * renaming .construct -> .model_construct * renaming .parse_obj -> .model_validate * make linters happy * add changes md-file Co-authored-by: Samuel Colvin <s@muelcolvin.com>
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.model_json_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.