HypothesisWorks / hypothesis

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
https://hypothesis.works
Other
7.58k stars 587 forks source link

Deprecate use of `@given()` inside `@given()` #4167

Open Zac-HD opened 1 week ago

Zac-HD commented 1 week ago

Nesting @given() inside @given() might seem reasonable at first glance - but there are major problems, and it doesn't actually give you any more power than using st.data() instead of an inner function. Those downsides include quadratic cost of generating examples, and considerably worse when shrinking; and outright incompatibility with some alternative backends.

@tybug checked a github dataset, and there are only five cases across thousands of repos: one in each of ArielHorwitz/botroyale, chardet/chardet, and cgarciae/pypeln, and vyperlang/vyper has these two.

So let's detect this, emit a deprecation warning - which can explain how and why to use st.data() instead - and then we'll turn that into an error in the next major version.