I'm running a suite of tests (.py files) using nosetests. Using a classic
import pdb; pdb.set_trace()
the nosetests run just never completes. It just hangs right where the breakpoint has been set, but never drops into the pdb debugger.
Any ideas why this would be? I've tried moving the breakpoint to a number of different positions (other test functions, other files) to no avail.
It's import pdb; pdb. set_trace() . When execution reaches this point in the program, the program stops and you're dropped into the pdb debugger. Effectively, this is the same as inserting a breakpoint on the line below where we call set_trace() .
pdb. set_trace (*, header=None) Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even if the code is not otherwise being debugged (e.g. when an assertion fails). If given, header is printed to the console just before debugging begins.
Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
Whenever you want to leave the pdb console, type the command quit or exit . If you would like to explicitly restart a program at any place within the program, you can do so with the command run .
Run nose with the -s
/ --nocapture
option and you'll be able to see the pdb prompt and interact with the debugger normally.
If using the commandline that means:-
python manage.py test -s [other-opts-and-args]
Nose is capturing the output and redirecting it. So, the breakpoint is hit, but you just don't see it. You need to turn off the output redirection so that the debug output shows up on the screen.
Nose can do this for you, if you use:
from nose.tools import set_trace; set_trace()
instead of:
import pdb;pdb.set_trace()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With