How to execute ipdb.set_trace () while executing pytest tests

I use pytest for my test suite. During error detection in complex inter-component testing, I would like to place import ipdb; ipdb.set_trace() import ipdb; ipdb.set_trace() in the middle of my code to allow me to debug it.

However, since the pytest sys.stdin / sys.stdout ipdb traps fail. How can I use ipdb during testing with pytest.

I am not interested in switching 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.

+48
Apr 15 '13 at 19:05
source share
3 answers

The error occurs due to the output of py.test output.

You must run py.test with the -s option (disable capture output). For example:

 py.test -s my_test.py 
+74
May 6 '13 at 21:29
source share

Install the pytest-ipdb plugin and then use

 pytest.set_trace() 
+18
Jun 07 '13 at 22:40
source share

pytest-ipdb is unfortunately no longer supported.

The solution is to run pytest my_test.py --pdb --pdbcls=IPython.terminal.debugger:Pdb

From the reference:

 pytest -h --pdb start the interactive Python debugger on errors. --pdbcls=modulename:classname start a custom interactive Python debugger on errors. For example: --pdbcls=IPython.terminal.debugger:TerminalPdb 

The only difference is that TerminalPdb seems to issue erros, but Pdb does not ( Ipython docs ).

+7
Apr 12 '17 at 16:12
source share



All Articles