码迷,mamicode.com
首页 > 其他好文 > 详细

unittest的使用三——断言

时间:2018-07-05 14:50:56      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:ESS   inf   bsp   unit   col   elf   hat   断言   exception   

常用的断言有3种:

判断两个值是不是都相等,参数分别是第一个值,第二个值,msg代表不想等的话,描述的信息

def assertEqual(self, first, second, msg=None):
"""Fail if the two objects are unequal as determined by the ‘==‘
operator.
"""
assertion_func = self._getAssertEqualityFunc(first, second)
assertion_func(first, second, msg=msg)

判断返回的是不是true

def assertTrue(self, expr, msg=None):
"""Check that the expression is true."""
if not expr:
msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
raise self.failureException(msg)

判断返回的两个值是不是不想等

def assertNotEqual(self, first, second, msg=None):
"""Fail if the two objects are equal as determined by the ‘!=‘
operator.
"""
if not first != second:
msg = self._formatMessage(msg, ‘%s == %s‘ % (safe_repr(first),
safe_repr(second)))
raise self.failureException(msg)

技术分享图片

 

unittest的使用三——断言

标签:ESS   inf   bsp   unit   col   elf   hat   断言   exception   

原文地址:https://www.cnblogs.com/peiminer/p/9267983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!