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 事后异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 pycharm/pydev 中调试 pytest 事后异常
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
