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
Improve the error message for HealthCheck.function_scoped_fixture
#3018
Comments
Current error message for reference: hypothesis/hypothesis-python/src/hypothesis/extra/pytestplugin.py Lines 177 to 188 in 1023a9b
|
This is what one of my draft improvements ended up looking like: msg = """Function-scoped fixture {1!r} used by {0}
Function-scoped fixtures are not reset between examples generated by
`@given(...)`, which is often surprising and can cause subtle test bugs.
If you were expecting the fixture to run separately for each generated example,
then unfortunately you will need to find a different way to achieve your goal
(e.g. using a similar context manager instead of a fixture).
If you are confident that your test will work correctly even though the
fixture is not reset between generated examples, you can suppress this health
check to assure Hypothesis that you understand what you are doing.
""" I'm not entirely happy with it, but I like the general direction of where I was going. The three sentences highlight three key pieces of information:
I also like the idea of inserting hard line breaks, because relying on one auto-wrapped line ends up making things harder to read in some contexts. |
An alternate take on the final paragraph that tries to be a bit more practical about when to suppress the check:
|
Seeing #3017 reminded me that I had previously done some partial work on improving the error message for
HealthCheck.function_scoped_fixture
, but never got around to actually finishing it. So here's at least an initial write-up.On a whim I searched GitHub and Google for “HealthCheck.function_scoped_fixture”, and found a number of cases where users did not seem to end up with a good understanding of how to deal with the problem.
For example, I saw:
I think our current error message has a pitfalls:
The text was updated successfully, but these errors were encountered: