-
Notifications
You must be signed in to change notification settings - Fork 587
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
Deprecate use of assume
or reject
outside of tests
#3748
Deprecate use of assume
or reject
outside of tests
#3748
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
To merge, we'll also need a release note, AUTHORS entry, and some tests (which can use @checks_deprecated_behavior
).
@@ -24,6 +24,13 @@ | |||
|
|||
|
|||
def reject() -> NoReturn: | |||
context = _current_build_context.value | |||
if context is None: | |||
note_deprecation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context = _current_build_context.value | |
if context is None: | |
if _current_build_context.value is None: |
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
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
) callsassume
orreject
, 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.