Debugging pytest post mortem exceptions in pycharm/pydev(在 pycharm/pydev 中调试 pytest 事后异常)
问题描述
我想在不预先配置断点的情况下将 PyCharm 的内置 Pytest 运行器与调试器一起使用.
I would like to use the built in Pytest runner of PyCharm together with the debugger without pre-configuring breakpoints.
问题是我的测试中的异常被 Pytest 捕获,因此 PyCharm 的事后调试器无法处理异常.
The problem is that exceptions in my test are caught by Pytest so PyCharm's post mortem debugger cannot handle the exception.
我知道使用断点是可行的,但我不想运行我的测试两次.
I know using a breakpoint works but I would prefer not to run my test twice.
在Unittest中找到了一种方法,我想知道Pytest中是否存在类似的东西.
Found a way to do this in Unittest, I would like to know if something like this exists in Pytest.
有没有办法用PyCharm?
推荐答案
你在用 pytest-pycharm 插件?看起来它对我有用.创建virtualenv,pip install pytest pytest-pycharm
,在PyCharm使用这个virtualenv Edit configuration ->Python Interpreter
然后用 Debug ...
运行示例:
Are you using pytest-pycharm plugin? Looks like it works for me. Create virtualenv, pip install pytest pytest-pycharm
, use this virtualenv at PyCharm Edit configuration -> Python Interpreter
and then run with Debug ...
Example:
import pytest
def test_me():
assert None
if __name__ == '__main__':
pytest.main(args=[__file__])
PyCharm 调试器在 assert None
点停止,(
PyCharm debugger stops at assert None
point, with (<class '_pytest.assertion.reinterpret.AssertionError'>, AssertionError(u'assert None',), None)
设置首选项>工具 >Python 集成工具 >默认测试运行程序
到 py.test.然后 运行 >在 test_me.py 中调试 'py.test'
这篇关于在 pycharm/pydev 中调试 pytest 事后异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!