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 事后异常
基础教程推荐
- Kivy 使用 opencv.调整图像大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
