Skip to content
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

Conversation

nickcollins
Copy link
Contributor

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.

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.
Copy link
Member

@Zac-HD Zac-HD left a 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(
Copy link
Member

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.

hypothesis-python/src/hypothesis/control.py Outdated Show resolved Hide resolved
Comment on lines +27 to +28
context = _current_build_context.value
if context is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
@nickcollins
Copy link
Contributor Author

I kinda got mixed up on the commits for this branch, so I've gone ahead and created a separate branch for this.
I'll put up a new pull request for that later this week, once I've addressed all the comments in the review

@nickcollins
Copy link
Contributor Author

Where should I place the test? I've grepped around in hypothesis-python/tests a bit but I couldn't really find a home for "X-is-deprecated" tests nor for "tests-about-assume/reject". Is there some particular file or folder where these kinds of tests live? Thanks!

@Zac-HD
Copy link
Member

Zac-HD commented Sep 22, 2023

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.

@nickcollins
Copy link
Contributor Author

Ok I have created a new PR #3751 from a new branch, i believe it has everything necessary.

@nickcollins nickcollins deleted the no-assume-outside-context branch September 25, 2023 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants