How to execute ipdb.set_trace() at will while running pytest tests

manu picture manu · Apr 15, 2013 · Viewed 26.5k times · Source

I'm using pytest for my test suite. While catching bugs in complex inter-components test, I would like to place import ipdb; ipdb.set_trace() in the middle of my code to allow me to debug it.

However, since pytest traps sys.stdin/sys.stdout ipdb fails. How can I use ipdb while testing with pytest.

I'm not interested in jumping to pdb or ipdb after a failure, but to place breaks anywhere in the code and be able to debug it there before the failure occurs.

Answer

petRUShka picture petRUShka · May 6, 2013

The error is raised because of py.test capturing output.

You should run py.test with -s option (turn off capture output). For example:

py.test -s my_test.py