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

PythonPdbNosetests

Python Problem Overview


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.

Python Solutions


Solution 1 - Python

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]

Solution 2 - Python

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

Solution 3 - Python

In my case the flag the flag -s/--nocapture, still didn't resolve it and drop the compiler into pdb.

One other reason that you could look into is if you're using a database such as MySQL as part of your tests, that it's not locked by another simultaneous process. In my case, i had started a python shell to query the MySQL database through SQL Alchemy and that had locked up the tables. As a result, my nose tests were hanging - not running/exiting.

I killed the python processes which were locking up the tables and Nose was back up sniffing

> $ ps auxww | grep python | awk '{print $2}' | sudo xargs kill -9

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBodhiView Question on Stackoverflow
Solution 1 - PythonstderrView Answer on Stackoverflow
Solution 2 - PythonJoe L.View Answer on Stackoverflow
Solution 3 - PythonShankar ARULView Answer on Stackoverflow