Skip to content

Deprecate use of assume or reject outside of tests #3748#3751

Merged
Zac-HD merged 11 commits intoHypothesisWorks:masterfrom
nickcollins:no-assume-outside-context-4
Sep 25, 2023
Merged

Deprecate use of assume or reject outside of tests #3748#3751
Zac-HD merged 11 commits intoHypothesisWorks:masterfrom
nickcollins:no-assume-outside-context-4

Conversation

@nickcollins
Copy link
Copy Markdown
Contributor

@nickcollins nickcollins commented Sep 22, 2023

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 branch 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.

A continuation of #3748 because I messed up the branch on that one and had to create a new branch.

Fixes #3743 and fixes #3753.

@nickcollins
Copy link
Copy Markdown
Contributor Author

Some of the tests are failing, including at least one of the tests I wrote, but I don't know how to read the test output to see what is wrong. Is there a way I can run the tests without adding a commit and invoking the CI?

@Zac-HD
Copy link
Copy Markdown
Member

Zac-HD commented Sep 24, 2023

You can click the "details" link next to the checks below this comment, which will lead e.g. here. You can run them locally with e.g. make format or make check-py310-cover; more details here.

Comment thread hypothesis-python/RELEASE.rst Outdated
Comment on lines +3 to +4
Deprecate use of :func:`~hypothesis.control.assume` and
:func:`~hypothesis.control.reject` outside of tests. No newline at end of file
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
Deprecate use of :func:`~hypothesis.control.assume` and
:func:`~hypothesis.control.reject` outside of tests.
Deprecate use of :func:`~hypothesis.assume` and :func:`~hypothesis.reject` from
outside a Hypothesis context, because these functions work by raising a special exception.

important to note that it's not "outside a test", but outside a particular kind of test. I think it's worth explaining why, too, and would do both in the deprecation message.

nickcollins and others added 9 commits September 24, 2023 01:55
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
Copy link
Copy Markdown
Member

Zac-HD commented Sep 24, 2023

...this has turned out to trigger some complicated latent issues in our engine, which are way more complicated than I anticipated. I'll push a commit to fix that, and then merge 🚀

@Zac-HD Zac-HD force-pushed the no-assume-outside-context-4 branch 2 times, most recently from fec0179 to 3a58f45 Compare September 24, 2023 19:28
@Zac-HD Zac-HD enabled auto-merge September 24, 2023 19:58
@nickcollins
Copy link
Copy Markdown
Contributor Author

Ok, thanks!

@Zac-HD Zac-HD disabled auto-merge September 24, 2023 23:36
@Zac-HD Zac-HD enabled auto-merge September 24, 2023 23:49
@Zac-HD Zac-HD merged commit 61b2940 into HypothesisWorks:master Sep 25, 2023
@nickcollins nickcollins deleted the no-assume-outside-context-4 branch September 25, 2023 19:39
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.

Static type check fails for proposed everything_except() recipe. UnsatisfiedAssumption masks runtime exceptions in execute_example

2 participants