Sometimes when I run pytest + hypothesis and one property-based test fails, I want to run that particular example with breakpoints etc.
@given(a=st.integers())
def test(a):
assert a != 4
Currently, I take the test function definition, add that particular case as @pytest.mark.parametrize and comment out all the hypothesis parametrizations. It is a bit annoying, because the argument structure of parametrize is somewhat different from @example.
# @given(a=st.integers())
@pytest.mark.parametrize("a", 4)
def test(a):
breakpoint()
assert a != 4
I tried just letting it stand as @example and commenting out the @given, but hypothesis does not permit that.
# @given(a=st.integers())
@example(a=4)
def test(a):
breakpoint()
assert a != 4
What is the most convenient way to debug exactly one example from a property-based test using hypothesis and pytest?
You'll want to use the
phasessetting, probably via a settings profile if you don't want to edit source code to add a decorator: