【发布时间】:2016-11-24 11:08:06
【问题描述】:
我通常在 python 中进行一些单元测试。我得到下面提到的 AssertionError。我想检查温度范围,如果它小于 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
================================================ ========================
失败:test_data_temp (main.ParseCSVTest)
Traceback (most recent call last):
File "try.py", line 36, in test_data_temperature
30 > ali > 25, True
AssertionError: False != True
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']
我很困惑如何检查它的范围并做出断言以使其通过测试。如果有人给出提示或示例。我会很感激的。
【问题讨论】:
-
如果它是一个列表,那么它在 30 到 25 之间确实是不正确的。
标签: python unit-testing assertion