Deprecate use of assume or reject outside of tests#3748
Deprecate use of assume or reject outside of tests#3748nickcollins wants to merge 2 commits intoHypothesisWorks:masterfrom
assume or reject outside of tests#3748Conversation
If some code outside a test (e.g. `execute_example`) calls `assume` or `reject`, they raise `UnsatisfiedAssumption`, which is an internal exception that should generally not seen by user code. This commit provides a warning deprecating such use cases, which helps clarify to the user that they are getting the exception because they have called these functions from the wrong places.
Zac-HD
left a comment
There was a problem hiding this comment.
Thanks for the PR!
To merge, we'll also need a release note, AUTHORS entry, and some tests (which can use @checks_deprecated_behavior).
| def reject() -> NoReturn: | ||
| context = _current_build_context.value | ||
| if context is None: | ||
| note_deprecation( |
There was a problem hiding this comment.
We'll also need to from hypothesis._settings import note_deprecation above.
| context = _current_build_context.value | ||
| if context is None: |
There was a problem hiding this comment.
| context = _current_build_context.value | |
| if context is None: | |
| if _current_build_context.value is None: |
Co-authored-by: Zac Hatfield-Dodds <[email protected]>
|
I kinda got mixed up on the commits for this branch, so I've gone ahead and created a separate branch for this. |
|
Where should I place the test? I've grepped around in |
|
Wow, there's really no good answer for that! After grepping around a lot I guess I'd go with https://github.com/HypothesisWorks/hypothesis/blobaster/hypothesis-python/tests/cover/test_control.py but mostly just because that's where I'd expect checks related to the current build context to live if it's otherwise unclear. |
|
Ok I have created a new PR #3751 from a new branch, i believe it has everything necessary. |
If some code outside a test (e.g.
execute_example) callsassumeorreject, they raiseUnsatisfiedAssumption, which is an internal exception that should generally not seen by user code. This commit provides a warning deprecating such use cases, which helps clarify to the user that they are getting the exception because they have called these functions from the wrong places.