pytest 断言

  • 断言:一个标准的用例都包含了断言,编写pytest自动化脚本的时候,也需要设置断言
  • assert使用
    • 常用分三种 1:比较大小与是否相等 2:包含或不包含  3:验证boolean
  • 例子
    • 比较大小
    • #coding: UTF-8
      import pytest
      # 比较大小与是否相等
      def test_assert_equal
      assert 2+2==2*2
      class Test_Class():
      def test_assert_equal(self):
      assert 4==3
      def test_assert_noequal(self):
      assert 4!=3
      def test_assert_greater(self):
      assert 4>=3
      if __name__ == '__main__':
      pytest.main("-v -s assert_001_equal_test.py")
    • 包含
      #coding: UTF-8
      import pytest
      # 测试包含或不包含
      def test_in():
      a = "Hello,Jerry"
      b = "Hello"
      assert b in a def test_not_in():
      a = "Hello,Jerry"
      b = "Jerry"
      assert b not in a class Test_Class():
      def test_in(self):
      a = "Hello,Jerry"
      b = "Hello"
      assert b in a if __name__ == '__main__':
      pytest.main("-v -s assert_002_contain_test.py")
    • 验证boolean
      #coding: UTF-8
      import pytest
      def check(flag):
      if flag!=0:
      return True
      else:
      return False
      def test_boolean():
      assert check(1)
      class Test_Boolean_Assert():
      def test_boolean(self):
      assert check(0) if __name__ == '__main__':
      pytest.main("-v -s assert_003_boolean_test.py")

欢迎一起交流(群号:575479860)

最新文章

  1. 学习ASP.NET MVC(三)——我的第一个ASP.NET MVC 视图
  2. 转:C#精髓 第四讲 GridView 72般绝技
  3. Factorial Trailing Zeroes
  4. win下php5.5.12装不上memcache扩展
  5. 【BZOJ】【1532】【POI2005】Kos-Dicing
  6. XCode6.1中的ios7.1适配
  7. hdoj 1702 ACboy needs your help again!【数组模拟+STL实现】
  8. javascript学习代码-判断闰年
  9. 黑白图像(DFS)
  10. myeclipse插件安装
  11. 关于url路径的定义方式
  12. mysql函数date_format统计刷选按年月日统计的数据
  13. POJ - 1422 Air Raid 二分图最大匹配
  14. [笔记] OS X and iOS 内核开发
  15. js十大排序算法
  16. 转载:IIS 之 连接数、并发连接数、最大并发工作线程数、队列长度、最大工作进程数
  17. Golang学习---常用库
  18. python之async-timeout模块
  19. malloc()參数为0的情况
  20. 问题1:jquery实现全选功能,第二次失效(已解决)

热门文章

  1. [译文]PHP千年虫(y2k compliance)
  2. IOS xcode 离线帮助文档安装和安装路径
  3. MySQL一致性非锁定读
  4. clear:both;和overflow:hidden;的应用理解。
  5. 怎么让Sublime Text不自动打开最近的文件/项目
  6. echarts学习笔记(部分angular及ant-design)
  7. git常用命令(二)
  8. ABP学习 解决:Update-Database : 无法将“Update-Database”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的问题
  9. C# while语句
  10. 前端css之文本操作及块级元素和行内元素