在pycharm/pydev中调试pytest post mortem异常

Sam*_*eka 9 python debugging unit-testing pytest pycharm

我想在不预先配置断点的情况下使用PyCharm的内置Pytest运行程序和调试器.

问题是我的测试中的异常被Pytest捕获,因此PyCharm的post mortem调试器无法处理异常.

我知道使用断点工作,但我不想两次运行我的测试.

在Unittest中找到了这样做的方法,我想知道Pytest中是否存在这样的东西.

有没有办法用PyCharm捕获unittest异常?

Ser*_*kiy 9

你在使用pytest-pycharm插件吗?看起来它适合我.创建virtualenv,pip install pytest pytest-pycharm在PyCharm中使用这个virtualenv,Edit configuration -> Python Interpreter然后运行Debug ...Example:

import pytest

def test_me():
    assert None

if __name__ == '__main__':
    pytest.main(args=[__file__])
Run Code Online (Sandbox Code Playgroud)

PyCharm调试器停止在assert None一点上,与(<class '_pytest.assertion.reinterpret.AssertionError'>, AssertionError(u'assert None',), None)

编辑

设置 Preferences > Tools > Python Integration Tools > Default test runnerpy.test.然后Run > Debug 'py.test in test_me.py'