Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdb.set_trace() causing frozen nosetests, does not drop into debugger

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.

like image 887
Bodhi Avatar asked Jan 26 '12 03:01

Bodhi


People also ask

What does import pdb pdb Set_trace () do?

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() .

What is pdb 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.

How do I use pdb debugger in Python?

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().

How do I break out of pdb?

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 .


2 Answers

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] 
like image 198
stderr Avatar answered Sep 19 '22 11:09

stderr


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() 
like image 25
Joe L. Avatar answered Sep 21 '22 11:09

Joe L.