Discuss / Python / ValueError not raised

ValueError not raised

Topic source

苏先sir

#1 Created at ... [Delete] [Delete and Lock User]

...F

FAIL: test_invalid (main.TestStudent)

Traceback (most recent call last): File "C:\Users\MRSU~1\AppData\Local\Temp\learn_python_gxpw3xgy_py\test_3.py", line 39, in test_invalid s1.get_grade() AssertionError: ValueError not raised


Ran 4 tests in 0.001s

FAILED (failures=1) !!!!!!我只是修改了class中的if语句,下面的测试模块没有改动,不知道怎么修改。

苏先sir

#2 Created at ... [Delete] [Delete and Lock User]

谢谢大家了,新手上路,请多指导!

解释器报错已经很清楚了,就是ValueError没有抛出,所以在小于-1和大于100的情况下加上一句raise ValueError让错误抛出即可


  • 1

Reply