How to debug tests with pdb


(Vincent Bastos) #1

Is it possible to debug unit tests and scenario tests using pdb and stepping through lines of code and checking variable values?

I know it is possible to run python -m pdb myscript.py on a particular script but is it possible to do this on python setup.py test?


(Sergi Almacellas Abellana) #2

I normally include the lines:

import pdb; pdb.set_trace()

On the source code line where I want to start the debugger.
Then running the test with the normal parameter will launch the debugger when the line is reached.

P.S: If you are on python3.7 you can use the new breakpoint function.


(Diego Abad) #3

On unit test I also use pdb.
Can I use pdb to debug scenarios (rst files)?


(Sergi Almacellas Abellana) #4

Yes, youe just have to include the same line on the test scenario:

import pdb; pdb.set_trace()

If you include on the source code the debugger will be also openend when running the test scenario.