* Configure Hypothesis * Hypothesis plugin docs * Add Hypothesis plugin Co-authored-by: Samuel Colvin <s@muelcolvin.com>
1.5 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.
Example tests
{!.tmp_examples/hypothesis_property_based_test.py!}
(This script is complete, it should run "as is")
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.