Pytest 断言
2024-09-04 12:42:01
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)
最新文章
- 学习ASP.NET MVC(三)——我的第一个ASP.NET MVC 视图
- 转:C#精髓 第四讲 GridView 72般绝技
- Factorial Trailing Zeroes
- win下php5.5.12装不上memcache扩展
- 【BZOJ】【1532】【POI2005】Kos-Dicing
- XCode6.1中的ios7.1适配
- hdoj 1702 ACboy needs your help again!【数组模拟+STL实现】
- javascript学习代码-判断闰年
- 黑白图像(DFS)
- myeclipse插件安装
- 关于url路径的定义方式
- mysql函数date_format统计刷选按年月日统计的数据
- POJ - 1422 Air Raid 二分图最大匹配
- [笔记] OS X and iOS 内核开发
- js十大排序算法
- 转载:IIS 之 连接数、并发连接数、最大并发工作线程数、队列长度、最大工作进程数
- Golang学习---常用库
- python之async-timeout模块
- malloc()參数为0的情况
- 问题1:jquery实现全选功能,第二次失效(已解决)
热门文章
- [译文]PHP千年虫(y2k compliance)
- IOS xcode 离线帮助文档安装和安装路径
- MySQL一致性非锁定读
- clear:both;和overflow:hidden;的应用理解。
- 怎么让Sublime Text不自动打开最近的文件/项目
- echarts学习笔记(部分angular及ant-design)
- git常用命令(二)
- ABP学习 解决:Update-Database : 无法将“Update-Database”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的问题
- C# while语句
- 前端css之文本操作及块级元素和行内元素