【发布时间】:2021-10-09 21:04:41
【问题描述】:
当我尝试获取异常的值时,该值未正确断言。
import pytest
class CustomException(Exception):
"""Custom Exception"""
def raise_custom_exception():
raise CustomException("This is a test exception")
def test_custom_exception():
with pytest.raises(CustomException) as execinfo:
raise_custom_exception()
assert execinfo == "This is not being caught"
我正在检查异常的值是否与预期值相同,但 pytest 显示所有测试都通过,即使异常的预期值不正确。
➜ *_question pytest main.py
======================= test session starts ==========================
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/israteneda/*_question
collected 1 item
main.py . [100%]
====================== 1 passed in 0.01s =============================
【问题讨论】:
标签: pytest