使用pytest.raises来进行对异常的测试
import pytest def test_error(): with pytest.raises(ZeroDivisionError): 1 / 0