-
Notifications
You must be signed in to change notification settings - Fork 584
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
How should we handle SystemExit? #2223
Comments
I think it makes sense to treat SystemExit and GeneratorExit like we do normal exceptions when raised from both strategies and test functions. This requires some changes, as when they arise from test functions they are currently handled more like KeyboardInterrupt, in particular not triggering Flaky if raised some times and not others. |
I feel like This doesn't necessarily mean that they should be handled differently though. I do think they're fundamentally different from My inclination would be that |
Well, one way GeneratorExit might appear is, if I recall correctly, nose uses (used?) generators to implement parametrized tests - you'd write a generator that yielded sets of arguments. If your test runner bailed out without running all the tests, that generator would receive a GeneratorExit as it exited "out the side" without finishing. But my reasoning was just that: both GeneratorExit and SystemExit are emitted deterministically by code, so checking for flakiness in their emission makes sense. The remaining question is whether a function under test should be able to actually exit from hypothesis testing with |
IMO "SystemExit ought to be deterministic and pytest treats it as a normal exception" is enough to justify us doing the same. |
In principle this can be solved by adding hypothesis/hypothesis-python/src/hypothesis/core.py Lines 468 to 477 in 6466600
And then writing a test that e.g. @given(st.integers())
def test(x):
if x > 100:
raise SystemExit prints output including |
PR #2189 demonstrates that we handle SystemExit (and GeneratorExit) in slightly inconsistent ways - if raised from inside a strategy it is handled like a normal exception; but if raised from within a test function it is captured and treated like KeyboardInterrupt in some ways, ensuring for example that it doesn't trigger "Flaky" if raised some of the time but not others. What is the correct behaviour?
The text was updated successfully, but these errors were encountered: