23

I want to use ipdb instead of pdb with py.test --pdb option. Is this possible? If so, how?

Clearly, I can use import ipdb; ipdb.set_trace() in the code but that requires to run the test, watch it fail, open a file, find the point of failure in said file, write the above line, re-run the tests. Lots of hassle if I could have something that by passes all of that.

2 Answers 2

27

Use this option to set custom debugger:

--pdbcls=IPython.terminal.debugger:Pdb

It can also be included in pytest.ini using addopts:

[pytest]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
4
  • 1
    in a file pytest.ini: [pytest] addopts = --pdbcls=IPython.terminal.debugger:Pdb
    – deterralba
    Commented Sep 7, 2018 at 8:52
  • 3
    So glad to find this! Note you also need the --pdb flag
    – Anentropic
    Commented Mar 25, 2019 at 11:21
  • 1
    If you have a more recent setup, you may need: [tool.pytest.ini_options] addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
    – iloveitaly
    Commented Nov 20, 2021 at 16:31
  • 1
    I actually recommend --pdbcls=IPython.terminal.debugger:TerminalPdb instead, which has full tab completion.
    – quazgar
    Commented Apr 16 at 8:48
8

Have you tried pytest-ipdb?

Looks like it's exactly what you are looking for?

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.