Skip to content
You're viewing docs for v1.10. See the latest version →

Hypothesis plugin

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.

Example tests

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.