【问题标题】:Debugging pytest post mortem exceptions in pycharm/pydev在 pycharm/pydev 中调试 pytest 事后异常
【发布时间】:2012-12-29 21:24:50
【问题描述】:

我想在不预先配置断点的情况下将 PyCharm 的内置 Pytest 运行器与调试器一起使用。

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

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

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

Is there a way to catch unittest exceptions with PyCharm?

【问题讨论】:

    标签: python unit-testing debugging pycharm pytest


    【解决方案1】:

    你在使用pytest-pycharm 插件吗?看起来它对我有用。创建 virtualenv,pip install pytest pytest-pycharm,在 PyCharm Edit configuration -> Python Interpreter 上使用这个 virtualenv,然后使用 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 runner 设置为py.test。然后Run > Debug 'py.test in test_me.py'

    【讨论】:

    • 它帮助了我!谢谢!
    • 请参阅this answer,了解如何使调试控制台与它一起工作!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 2017-04-04
    • 2020-04-25
    • 2021-06-22
    • 1970-01-01
    • 2018-08-19
    • 2022-11-28
    相关资源
    最近更新 更多