通过 py.test --pdb 选项使用 ipdb 而不是 pdb

Use ipdb instead of pdb with py.test --pdb option

我想使用 ipdb instead of pdb with py.test --pdb 选项。这可能吗?如果是,怎么做?

显然,我可以在代码中使用 import ipdb; ipdb.set_trace(),但这需要 运行 测试,观察它是否失败,打开一个文件,找到该文件中的失败点,写下上面的内容行,重新运行 测试。如果我能有一些东西绕过所有这些,那就麻烦多了。

你试过了吗pytest-ipdb

看起来这正是您要找的东西?

使用此选项设置自定义调试器:

--pdbcls=IPython.terminal.debugger:Pdb

它也可以包含在 pytest.ini 中使用 addopts:

[pytest]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"