比较变量,整数相同但类型不同(比较运算符)

2024-06-16 13:09:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个奇怪的测试步骤,我似乎不明白。基本上在一个测试框架中,我使用一个典型的“应该”和“是”来测试变量。返回的值相同,但该步骤仍然失败。经过一些繁琐的调试,我意识到失败的步骤也有不同的类型,尽管值相同,例如:

Test 3.3:     Check value
HL Value test: HL_CodingCounter == 2
Normal Value test: sysConfigRWData.codingCounter == 2
Should: {
    'sysConfigRWData.codingCounter': 2
    'HL_CodingCounter': 2
}
Is: {
    'sysConfigRWData.codingCounter': 2
    'HL_CodingCounter': 2
}
is: 2, <class 'mySitePackage.datapoints.DataPoint_CodingCounter'>:
should: 2, <type 'int'>:

delta 
Should: HL_CodingCounter: 2 
Is: HL_CodingCounter: 2
Is: 2, <type 'int'>:
Should: 2, <type 'int'>:

在这里您可以看到失败的是HL_CodingCounter,而不是另一个参数

那么,在Python中使用比较运算符(==)时,是否也会考虑type?如果是这样的话,我该如何规避这个问题,从而只考虑实际值呢


Tags: test框架isvaluetype步骤hlint