Pytest doesn’t play nicely with ipdb
To ensure breakpoint()
triggers ipdb
as my
default debugger, I used to set:
PYTHONBREAKPOINT=ipdb.set_trace`
in ~/.bash_profile
(following
this advice).
However, this doesn’t play nicely with Pytest’s output capturing.
Pytest has a useful feature where
it disables output capturing if breakpoint
is called during test execution,
which allows access to the debugger prompt. However, this only works if
PYTHONBREAKPOINT
is unset. If you have PYTHONBREAKPOINT
set to a non-empty
value, then you need to use Pytest’s
-s
option to disable all output capturing. But this isn’t generally desirable as it
can lead to lots of unnecessary output being printed to your terminal during
test runs.
Specifying --pdbcls=IPython.terminal.debugger:Pdb
doesn’t make any difference
if PYTHONBREAKPOINT
is set.
A decent work-around is to not set PYTHONBREAKPOINT
globally and install
pdb++
which provides much of the benefit of
ipdb
(e.g. syntax highlighting, tab completion) but doesn’t suffer from the
above problem; you can access the debugger without using the -s
option.
For projects that use ipdb
, you can set PYTHONBREAKPOINT
on a per-project
basis.