harborapi icon indicating copy to clipboard operation
harborapi copied to clipboard

Ensure `T` and `None` are tested for fields with type `Optional[T]`

Open pederhan opened this issue 3 years ago • 0 comments

As of now, Hypothesis does not seem to guarantee that it actually tests the type for Pydantic model fields with type Optional[T] with default value None. It seems to test with None only.

Using the solution outlined in this issue, we can use hypothesis-jsonschema to generate the required values.

This will require a somewhat large change to both the existing unit tests and the testing regime in general. Any new tests following this change will be required to use hypothesis-jsonschema. We could potentially also make use of st.register_type_strategy() to register the type strategy after inferring the strategy from the schema, so that other tests can simply use st.from_type()

pederhan avatar Dec 19 '22 08:12 pederhan