unittest提供了以下断言方式:

方法

检查

新进

assertEqual(a, b)

a == b

 

assertNotEqual(a, b)

a != b

 

assertTrue(x)

bool(x) is True

 

assertFalse(x)

bool(x) is False

 

assertIs(a, b)

a is b

3.1

assertIsNot(a, b)

a is not b

3.1

assertIsNone(x)

x is None

3.1

assertIsNotNone(x)

x is not None

3.1

assertIn(a, b)

a in b

3.1

assertNotIn(a, b)

a not in b

3.1

assertIsInstance(a, b)

isinstance(a, b)

3.2

assertNotIsInstance(a, b)

not isinstance(a, b)

3.2

所有assert方法都接受一个msg参数,该参数可以作为错误消息输出。例如:

assertEqual(firstsecondmsg=None)

  比较first和second是否相等,不相等可以指定输出msg,测试失败

assertNotEqual(firstsecondmsg=None)

  比较first和second是否不相等,如果值相等,则输出失败

assertTrue(exprmsg=None)

assertFalse(expr,msg=None)

  测试expr为true或者false

assertIs(firstsecondmsg=None)

assertIsNot(firstsecondmsg=None)

  判断first和second是否为同一对象

assertIsNone(exprmsg=None)

assertIsNotNone(exprmsg=None

  判断expr是否为None

assertIn(firstsecondmsg=None)

assertNotIn(firstsecondmsg=None)

  判断first是否在second中

assertIsInstance(objclsmsg=None)

assertNotIsInstance(objclsmsg=None)

  判断obj是否为cls的实例

最新文章

  1. 为什么基于Windows Server 2008 R2的网络负载均衡(NLB)配置的时候总会报错“主机不可访问”?
  2. Qt、VTK配置常见问题
  3. C#中三种定时器对象的比较
  4. Linux编译内核提示'make menuconfig' requires the ncurses libraries错误
  5. OC语言--NSFileManager& NSFileHandle
  6. IDEA新建SpringMVC项目报错解决办法
  7. IOS APP IDs
  8. aps.net js获取服务器控件
  9. 超炫的Button按钮展开弧形动画效果
  10. DB Query Analyzer 6.03, the most excellent Universal DB Access tools on any Microsoft Windows OS
  11. 解决Linux(Loaded plugins: fastestmirror Please use /usr/bin/yum --help)
  12. tensorflow学习之(八)使用dropout解决overfitting(过拟合)问题
  13. linux上部署SpringBoot项目及遇到的问题
  14. 1411 - Ants(巨人与鬼)
  15. js 压缩上传的图片方法(默认上传的是file文件)
  16. CF949D Curfew
  17. if、else、elif
  18. 鸟哥的Linux私房菜——第八章
  19. delphi TOnFormVisibleChangeEvent 事件应用
  20. BackgroundWorker+ProgressBar+委托 实现多线程、进度条

热门文章

  1. [POI2010] GIL-Guilds - 二分图染色,DFS
  2. PP: Articial Intelligence—TheRevolution Hasn’t HappenedYet
  3. Linux shell unzip和tar 批量解压文件
  4. 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Banana
  5. yii2 钩子函数
  6. element-ui的upload组件的clearFiles方法
  7. 数据预处理 | python 第三方库 imblearn 处理样本分布不均衡问题
  8. Struts2学习-struts.xml文件配置
  9. [Agc001A/At1979] BBQ Easy - 贪心
  10. ActiveMQ使用JDBC持久化