How to debug tests with pdb

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 on a particular script but is it possible to do this on python test?

1 Like

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.


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

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.