简体   繁体   中英

How do I exit from pdb debugging when running hypothesis?

I like using hypothesis for my unit tests. I also like using pdb for debugging when things go wrong. But trying to use these two together can be very annoying. If I set a breakpoint in a file that is run by hypothesis using pytest <PATH-TO-FILE> -s , it will stop at the breakpoint as expected, and I can do my analysis. But after I am done, I want to be able to exit out of the test. However, if I do ctrl+c from inside the breakpoint, the test doesn't quit, it simply goes to the next hypothesis test case. And I have to keep doing this until hypothesis is done generating all it's test cases.

I usually end up opening system monitor and killing the pytest process everytime I want to be able to quit the test.

I'm hoping there is a better way.

The issue can be reproduced by the following snippet -

import hypothesis
from hypothesis import strategies as st

@hypothesis.given(st.integers())
def test_some_function(some_arg):
    breakpoint()
    print(some_arg)

test_some_function()

I am using python 3.8 with hypothesis 5.37.0

This happens under Linux but not under Windows, and it's unclear whether or not that's a bug in Hypothesis, or in Pdb, or 'just' undesirable behaviour from a combination of features.

As a workaround , you can import os; os._exit(0) import os; os._exit(0) to skip all cleanup logic and exit instantly.

A better, albeit somewhat more involved, solution is to disable multi-bug reporting and the shrinking phase when you use a debugger, so that Hypothesis stops generating examples immediately after the first failure. You can create a settings profile for use with the debugger, and then activate it via the --hypothesis-profile= argument to pytest .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM