我想将 PyCharm 的内置 Pytest 运行器与调试器一起使用,而无需预先配置断点。
问题是 Pytest 捕获了我测试中的异常,因此 PyCharm 的事后调试器无法处理异常。
我知道使用断点是可行的,但我不希望我的测试运行两次。
在 Unittest 中找到了一种方法,我想知道 Pytest 中是否存在类似的东西。
最佳答案
你在使用 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 runner
到 py.test。然后 Run > Debug 'py.test in test_me.py'
关于python - 在 pycharm/pydev 中调试 pytest 事后异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086067/