assertequal用法python_assertEqual和assertIs之间有什么区别(assertIs是在Python 2.7中引入的)?...
assertEqual(a, b) # checks that a == b
assertIs(a, b) # checks that a is b
解決方法:
使用assertEqual這兩個對象不需要是同一類型,它們只需要是相同的值.相比之下,使用assertIs,兩個對象需要是同一個對象.
斷言的assertEqual測試,如==運算符:
The operators , ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily.
assertI測試對象標(biāo)識與is相同而不是運算符:
The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value.
以上引用均來自Python文檔部分5.9 Comparisons.
標(biāo)簽:python,unit-testing
來源: https://codeday.me/bug/20191008/1870437.html
總結(jié)
以上是生活随笔為你收集整理的assertequal用法python_assertEqual和assertIs之间有什么区别(assertIs是在Python 2.7中引入的)?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jquery遍历多个li_jQuery中
- 下一篇: 金蝶kis商贸采购单商品代码_金蝶KIS