我想将 PyCharm 的内置 Pytest 运行器与调试器一起使用,而无需预先配置断点。
问题是我的测试中的异常被 Pytest 捕获,因此 PyCharm 的事后调试器无法处理该异常。
我知道使用断点是有效的,但我不想运行两次测试。
在 Unittest 中找到了一种方法,我想知道 Pytest 中是否存在类似的东西。
有没有办法用 PyCharm 捕获单元测试异常?
你正在用吗pytest-pycharm插入?看起来这对我有用。创建虚拟环境,pip install pytest pytest-pycharm
,在 PyCharm 中使用这个 virtualenvEdit configuration -> Python Interpreter
然后运行Debug ...
例子:
import pytest
def test_me():
assert None
if __name__ == '__main__':
pytest.main(args=[__file__])
PyCharm 调试器停止于assert None
点,与(<class '_pytest.assertion.reinterpret.AssertionError'>, AssertionError(u'assert None',), None)
EDIT
Set Preferences > Tools > Python Integration Tools > Default test runner
to py.test. Then Run > Debug 'py.test in test_me.py'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)