New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for hypothesis #261
Comments
This would be really cool to have support for. I have no experience from registering custom hypothesis strategies, but my first instinct is I suspect they will need to be quite bespoke per type. We also need to consider how we can introduce this without requiring hypothesis to be installed, but that should be doable. |
I also am not very experienced with constructing hypothesis strategies, but its mostly looking like generator chaining. I guess looking at the default strategies for number types and container types should be quite helpful, and for general predicates the user will need to provide the strategy using the hook. Checking if it is installed is easy - something like try:
import hypothesis
_HAS_HYPOTHESIS = True
except ImportError:
_HAS_HYPOTHESIS = False which is done only once say in |
Hello! I'm a maintainer of Hypothesis (and a fan of phantom types!) and I happened to come across this. You might be interested in using an entry point to automatically register strategies only when hypothesis is imported. |
@rsokl Thanks for chiming in, that looks great and like exactly what we need! 🙏 I just ran into a case where I'd want Hypothesis + phantom-types for a work thing, so I might take a stab at this soonish. |
I have WIP going, but I haven't yet fully convinced myself I want to do it this way, with inheritance, or whether strategy registration should be more separated. |
#262 is now merged. |
I currently wanted to add hypothesis to my tests and I use phantom types in my pydantic models. Hypothesis has built-in support for pydantic, but it turns out it does not work with phantom types.
results in
but works when registering the type strategy (line in example is uncommented)
Would it be possible to register the corresponding generating strategies for all built-in types and provide a hook like
__hypothesis_strategy__
where an automatic strategy is not feasible / to override the default one?I think that probably should be done in the metaclass, so the strategy is registered whenever a type is defined and hypothesis is installed in the environment.
The text was updated successfully, but these errors were encountered: