Devin Devin - 2 months ago 17x
Python Question

setting breakpoints with nosetests --pdb option

Nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is.

However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package).

How can I set breakpoints before the tests are executed?
Currently I'm using:

python -m pdb /path/to/my/nosetests

This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g. arrow keys) are broken.

Using import pdb; pdb.set_trace() would seem like a good idea, however nosetests is blocking my access to the pdb console.


You can add

import pdb; pdb.set_trace() 

anywhere in your source that you want to stop in the debugger.

Make sure you pass -s to nose so that it does not capture stdout.