import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError) as excinfo://在該上下文下寫跑一場的函數
1 / 0
assert excinfo.type == ZeroDivisionError # 斷言異常類型type
assert "division by zero" in str(excinfo.value) # 斷言異常value值
參考:
https://learning-pytest.readthedocs.io/zh/latest/doc/test-function/exception.html
https://www.cnblogs.com/yoyoketang/p/9469996.html