-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Enhancement: support creation of Hypothesis strategies #387
Comments
Yes :) See my https://sobolevn.me/2021/02/make-tests-a-part-of-your-app article, feel free to assign some tasks on me. |
That's great! I'll try to get the basic structure ready for it, and then you can make improvements/changes in that branch? Also, for the following case from your article: import deal
@deal.pre(lambda a, b: a >= 0 and b >= 0)
@deal.raises(ZeroDivisionError) # this function can raise if `b=0`, it is ok
def div(a: int, b: int) -> float:
return a / b Do you think at some point def div(a: Annotated[int, Ge(0)], b: Annotated[int, Ge(0)]) -> float:
return a / b
a = -1
b = 23
div(a, b) # type check error
if a >= 0 and b >= 0:
div(a, b) # no type check error |
By design mypy won't treat |
Oh this is really cool |
Summary
I was playing around with hypothesis and noticed that it can't create strategies when there are constraints on the fields. So, I'm proposing that
polyfactory
supports creation of strategies for a given model, with the constraints being respected.Currently, there seems to be plans to support this as seen in this issue, however that would require the users use the annotated types for the constraints. Furthermore, while pydantic v1 did use to integrate with hypothesis, the latest version does not so as documented here.
Would this be something that would be helpful and worth implementing? Opinions, @litestar-org/members?
Basic Example
Drawbacks and Impact
No response
Unresolved questions
No response
Funding
The text was updated successfully, but these errors were encountered: