python - 在 pycharm/pydev 中调试 pytest 事后异常

标签 python unit-testing debugging pycharm pytest

我想将 PyCharm 的内置 Pytest 运行器与调试器一起使用,而无需预先配置断点。

问题是 Pytest 捕获了我测试中的异常,因此 PyCharm 的事后调试器无法处理异常。

我知道使用断点是可行的,但我不希望我的测试运行两次。

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

Is there a way to catch unittest exceptions with PyCharm?

最佳答案

你在使用 pytest-pycharm插入?看起来对我有用。创建虚拟环境,pip install pytest pytest-pycharm ,在 PyCharm 使用这个 virtualenv Edit 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)

编辑

设置Preferences > Tools > Python Integration Tools > Default test runnerpy.test。然后 Run > Debug 'py.test in test_me.py'

关于python - 在 pycharm/pydev 中调试 pytest 事后异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086067/

相关文章:

python - 导入错误 : No module named when module is there

python - 根据 txt 文件的搜索结果分配变量值

python - 根据python中的列表替换列中的几个值

java - 如何在 Java 中比较 SQL 语句的功能相等?

c++ - 确定 Visual Studio 2015 调试器中每个帧的堆栈大小

python - 在 Windows 上调查 USB 设备的最佳工具是什么

java - 接受类参数的测试方法

unit-testing - 在 Jest 中,当使用函数生成 describe/it block 时,有没有办法让 beforeAll/beforeEach block 在断言之前运行?

IOS 应用程序以调试器错误结束,只是 (lldb)

debugging - 如何让gdb每次启动时都运行用户定义的函数(在.gdbinit中定义)?