assertequal用法python_assertEqual和assertIs之间有什么区别(assertIs是在Python 2.7中引入的)?...
assertEqual(a, b) # checks that a == b
assertIs(a, b) # checks that a is b
解決方法:
使用assertEqual這兩個(gè)對(duì)象不需要是同一類型,它們只需要是相同的值.相比之下,使用assertIs,兩個(gè)對(duì)象需要是同一個(gè)對(duì)象.
斷言的assertEqual測(cè)試,如==運(yùn)算符:
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測(cè)試對(duì)象標(biāo)識(shí)與is相同而不是運(yùn)算符:
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.
以上引用均來(lái)自Python文檔部分5.9 Comparisons.
標(biāo)簽:python,unit-testing
來(lái)源: https://codeday.me/bug/20191008/1870437.html
總結(jié)
以上是生活随笔為你收集整理的assertequal用法python_assertEqual和assertIs之间有什么区别(assertIs是在Python 2.7中引入的)?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: jquery遍历多个li_jQuery中
- 下一篇: python测试网站功能_Python检