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

The error is raised because pytest captures output by default.

You can run pytest with -s option (turn off capture output). For example:

py.test -s

and then in

import ipdb;

As of 2019-11 here is what should fix it:

pip install ipdb gnureadline ptpython

export PYTEST_ADDOPTS='--pdb --pdbcls=IPython.terminal.debugger:Pdb'

This is what I use

py.test tests/ --pdbcls=IPython.core.debugger:Pdb -s

pytest-ipdb is unfortunately not supported anymore.

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

From the help command:

pytest -h
  --pdb                 start the interactive Python debugger on errors.
                        start a custom interactive Python debugger on errors.
                        For example:

The difference is just that TerminalPdb seems to throw erros, but Pdb not (Ipython docs).