-
Notifications
You must be signed in to change notification settings - Fork 586
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
target() cannot be called outside a hypothesis test #2581
Comments
|
hypothesis/hypothesis-python/src/hypothesis/control.py Lines 173 to 175 in caccabb
I'd be happy to add an optional keyword-only argument like |
|
I'll give this a shot, if no one has yet |
|
Thanks to @PiDelport in #2675 (review), I've come around to the idea that instead of a special-case argument, we should provide a general predicate. For example: if hypothesis.currently_in_test_context():
# We're in an @given or stateful test, and can safely use e.g.
target(x)
event("hello")
assume(foo)
if bar: reject()This should still be documented as "only use this in test helper functions", but I think it would be of sufficient if niche interest to justify its existence - and more orthogonal/composable than supporting similar capabilities on a function-by-function basis. |
I have a test
assert_allclose_phasewhich checks whether two arrays are almost equal modulo one. When running underhypothesis, this seems like a sensible place to puttarget, albeit with a(n optional?)nameargument in case I want to call it twice in the same test. Unfortunately if I do so then I can't use the same function in non-hypothesistests:My current workaround is to call
targetonly ifnameis provided, but this clutters simple tests that wouldn't need aname.The text was updated successfully, but these errors were encountered: