天天看點

python assertionerror是什麼異常_python和AssertionError中的單元測試:False!=Tru

我正在用python做一些單元測試。我在下面提到斷言錯誤。我想檢查溫度範圍,如果它小于30,大于25,那麼代碼應該通過,但它給我錯誤。我不知道我在哪裡犯了錯誤。在test_csv_read_data_headers (__main__.ParseCSVTest) ... ok

test_data_fuelConsumption (__main__.ParseCSVTest) ... ok

test_data_temperature (__main__.ParseCSVTest) ...FAIL

test_data_timestamp (__main__.ParseCSVTest) ... ok

============================================================================

失敗:測試資料溫度(main.ParseCSVTest)

^{pr2}$

Ran 4 tests in 0.014s

FAILED (failures=1)

對于測試失敗的溫度部分,代碼如下所示。在def test_data_temperature(self):

column = [row[0].split()[3] for row in read_data(self.data)[1:]]

ali = column[0:4]

print ali

self.assertEqual(

30 > ali > 25, True

)

我用ali列印資料,它是以清單的形式['25.8', '25.6', '25.8', '25.8']

我很困惑,我如何檢查這個範圍,并作出斷言,以便它通過測試。如果有人給你一個提示或例子。我會非常感激的。在