Skip to content

Deprecate use of assume or reject outside of tests#3748

Closed
nickcollins wants to merge 2 commits intoHypothesisWorks:masterfrom
nickcollins:no-assume-outside-context
Closed

Deprecate use of assume or reject outside of tests#3748
nickcollins wants to merge 2 commits intoHypothesisWorks:masterfrom
nickcollins:no-assume-outside-context

Conversation

@nickcollins
Copy link
Copy Markdown
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
Copy Markdown
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).

def reject() -> NoReturn:
context = _current_build_context.value
if context is None:
note_deprecation(
Copy link
Copy Markdown
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.

Comment thread hypothesis-python/src/hypothesis/control.py Outdated
Comment on lines +27 to +28
context = _current_build_context.value
if context is None:
Copy link
Copy Markdown
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:

@nickcollins
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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