我已閱讀有關(guān)使用 pytest 創(chuàng)建異常的文檔,但不確定如何在我的代碼中定義異常。據(jù)說 OutOfRangeError 沒有定義。任何幫助表示贊賞。my_roman_module.py:def to_roman(n): '''converts integers/arabic numerals to Roman numerals''' if not (0<n<4000): raise OutOfRangeError('number out of range (must be between 1-3999)')result = ''for numeral, integer in roman_numerals: while n >= integer: result += numeral n -= integerreturn resulttest_my_roman_module.py:import pytestfrom my_roman_module import to_romandef test_not_in_range(): '''to_roman should fail with large input''' with pytest.raises(OutOfRangeError): to_roman(4000)
添加回答
舉報(bào)
0/150
提交
取消