在pycharm / pydev中调试pytest post mortem异常 [英] Debugging pytest post mortem exceptions in pycharm/pydev

查看:845
本文介绍了在pycharm / pydev中调试pytest post mortem异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PyCharm内置的Pytest运行器和调试器,而不需要预先配置断点。



问题是我的测试中的异常被捕获通过Pytest,PyCharm的post验证调试器无法处理异常。



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



在Unittest中找到一种方法,我想知道Pytest中是否存在类似的东西。



有没有办法用PyCharm捕获单元测试异常?

解决方案

您是否使用 pytest-pycharm 插件?看起来像对我有用创建virtualenv, pip install pytest pytest-pycharm ,在PyCharm中使用此virtualenv 编辑配置 - > Python解释器然后运行调试... 示例:

  import pytest 

def test_me():
assert无

如果__name__ =='__main__':
pytest.main (args = [__ file__])

PyCharm调试器停止在断言无(< class'_pytest.assertion.reinterpret.AssertionError'>,AssertionError(u'assert None',),None) / p>

编辑



设置首选项>工具> Python集成工具>默认测试运行器 py.test 。然后运行>在test_me.py'中调试'py.test'


I would like to use the built in Pytest runner of PyCharm together with the debugger without pre-configuring breakpoints.

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.

Found a way to do this in Unittest, I would like to know if something like this exists in Pytest.

Is there a way to catch unittest exceptions with PyCharm?

解决方案

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 debugger stops at assert None point, with (<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'

这篇关于在pycharm / pydev中调试pytest post mortem异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆