Debugging pytest post mortem exceptions in pycharm/pydev

匿名 (未验证) 提交于 2019-12-03 01:31:01

问题:

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?

回答1:

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 (, 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'



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!