Nosetests assert_equal显然不等于python ==

时间:2015-06-04 14:27:30

标签: python unit-testing dictionary nose

我为具有不同来源的设置编程温度控制(在此示例中只有一个):

source = Source()

sources_dict = {
    key: source
}

temp_control = TempControl(args) #A dictionary is built on instantiation based on args
                                 #and assigned to temp_control.sources

sources_dict使用相同的TempControl(args)定义。请参阅for循环的内容,了解哪些有效,哪些无效。

for key, value in tempControl.sources.iteritems():
    assert_equal(value, sources_dict[key]) #Fails
    tempControl.sources[key] == sources_dict[key] #Works
    value == sources_dict[key] #Works

如果没有,我收到以下错误消息:

AssertionError: <pvd_temp_control.Source object at 0x02AA63B0> !=   <pvd_temp_cont
rol.Source object at 0x02AA6330>
-------------------- >> begin captured stdout << ---------------------
sources_dict: {'Cu': <pvd_temp_control.Source object at 0x02AA6330>}
tempControl.sources: {'Cu': <pvd_temp_control.Source object at 0x02AA63B0>}
source: <pvd_temp_control.Source object at 0x02AA6330>
--------------------- >> end captured stdout << ----------------------

任何想法为什么?

1 个答案:

答案 0 :(得分:1)

我必须更加具体。 assert_equal不会做魔法并通过字典。这是正确的,例如:

for key, value in tempControl.sources.iteritems():
    assert_equal(value.element_name, sources_dict[key].key_name)