Skip to content

Fail more gracefully with breakpoint() - don't hang #1963

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

Closed
mscheifer opened this issue May 8, 2025 · 2 comments
Closed

Fail more gracefully with breakpoint() - don't hang #1963

mscheifer opened this issue May 8, 2025 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@mscheifer
Copy link

Is your feature request related to a problem? Please describe.
I've been using the built-in Python debugger Pdb which you can drop into by just adding breakpoint() since Python 3.7. Normally I run my tests with coverage but I have to remember to not do that, bypassing my normal unittest script, because the process will just hang and need to be killed.

Describe the solution you'd like
It would be nice if coverage could detect that a breakpoint was hit and abort.

Describe alternatives you've considered
If aborting isn't a good idea, coverage could print a message so that I know what's going on and can kill the process. Alternatively the process could somehow just work through a debug session but I don't actually need the coverage statistics when I'm debugging.

Additional context
#1337 seems related but the result of the interaction is different. In that issue the reporter says that breakpoints are skipped whereas here it seems like the breakpoints are hit but somehow coverage prevents the Pdb CLI from popping up.

@mscheifer mscheifer added the enhancement New feature or request label May 8, 2025
@nedbat
Copy link
Owner

nedbat commented May 8, 2025

This sounds interesting. I don't know how the debugger and coverage interact. I tried reproducing what you are seeing, but could not:

def product():
    print("Heloo")
    breakpoint()
    print("Bye")

def test_product():
    product()

Running pytest under coverage:

% coverage run -m pytest -n 0 bp.py

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /Users/ned/coverage/trunk/bp.py(4)product()
-> print("Bye")
(Pdb) c

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB continue (IO-capturing resumed) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.                                                                                                   [100%]
1 passed in 2.76s

Can you create a reproducible example, complete with configuration files, etc?

@nedbat nedbat added the question Further information is requested label May 8, 2025
@mscheifer
Copy link
Author

Ahh my bad. I should have tried to created a minimal example first. When I actually tried to do that now I realized the problem has nothing to do with coverage. It was the -b option in the unittest module. That apparently also buffers the debugger output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants