当前位置:网站首页>pytest 执行规则_基本用法_常用插件_常用断言_常用参数
pytest 执行规则_基本用法_常用插件_常用断言_常用参数
2022-07-26 10:50:00 【亚索不会吹风】
pytest 执行规则_基本用法_常用插件_常用断言_常用参数
命名规则
''' 1.py文件以test开头 2.文件内类名Test开头 3.文件内方法test开头 '''

class Testdemo:
def test_debug_xx(self):
# time.sleep(1)
print("-s打印调试信息")
def test_1(self):
print("测试错误重跑")
assert 1==2
def test_2(self):
print("测试错误重跑")
assert 1==2
def test_3_xx(self):
assert 1==1
常用参数
#主函数运行方式
if __name__ == '__main__':
''' 主函数传参数格式pytest.main(["参数1","参数2"]) -s 打印调试信息如:print -v 打印详细信息 test_case.py::Testdemo::test_1 PASSED 类名,方法名 -n 多线程运行用例,我的好像有问题 , "-n=2" --reruns 重跑用例可以设置次数 ,'--reruns=2' -x 一个用例报错,后续用例执行停止 --maxfail 设置几个用例失败后停止 ,'--maxfail=2' -k 运行包含指定字符的用例 ,'-k=xx' '''
pytest.main(['-vs',r"D:\python新代码集\pytest_study\basics\test_case.py",'-k=xx'])
实例
-s

-v

-n暂时我这里有问题,无法演示
–reruns
pytest.main(['-vs',r"D:\python新代码集\pytest_study\basics\test_case.py",'--reruns=2'])

-x 这里三条用例,第二条错误后停止了,只执行了2条

–maxfail 设置2个错误后停止执行
pytest.main([‘-vs’,r"D:\python新代码集\pytest_study\basics\test_case.py",‘–maxfail=2’])
-k 2个满足携带字符“xx”执行,2个不满足被忽略
pytest.main([‘-vs’,r"D:\python新代码集\pytest_study\basics\test_case.py",‘-k=xx’])
常用断言方式
import pytest
#判断是否为真(1>2,不对,为假,所有用例错误)
def test1():
assert 1>2
#判断不为真
def test2():
assert not 1>2
#判断in后面的包含前面的
def test3():
assert "1" in ["1","2","5"]
#等于
def test4():
assert 1==1
#不等于
def test5():
assert 1 == 1
常用插件
第二个是分布式多线程 -n参数用的插件
第三个是改变用例执行顺序的插件
第四个是失败重跑用的
第一个和第五个是生成html报告用的
边栏推荐
- 软件测试综述之软件测试的背景、实质、软件开发的过程
- 字典与int矩阵
- Bash shell learning notes (I)
- Sql Server 数据库之完整性约束
- 菜鸟看源码之HashTable
- Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
- Bash shell learning notes (4)
- [leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
- 使用flex实现左中右布局,中间自适应
- RT thread learning notes (VIII) -- start the elmfat file system based on SPI flash (Part 2)
猜你喜欢

Bash shell learning notes (II)

Software Testing Overview: the background, essence and process of software testing

用两个栈实现队列

35. Search the insertion position
![Error[pe147]: declaration is incompatible with 'error problem](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[pe147]: declaration is incompatible with 'error problem
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

Bash shell学习笔记(四)

RT thread learning notes (VI) -- start the elmfat file system based on SPI flash (Part 1)

按二进制数中1的个数分类

How to assemble a registry?
随机推荐
Sql Server 数据库之初学体验
ThreadPoolExecutor是怎样执行任务的
The problem of formatting IAR sprintf floating point to 0.0 in UCOS assembly
C语言命名空间的定义与使用
Halcon模板匹配之Shape
使用定位实现左中右布局,中间内容自适应
Flutter 防止科学计数并去除尾数无效0
回到顶部的几种方案(js)
flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
Constructors, method overloads, object arrays, and static
Fragment lazy load
2021-08-13 learn C language with pengge - array
MultipartFil转为File
nmap弱点扫描结果可视化转换
企鹅龙(DRBL)无盘启动+再生龙(clonezilla)网络备份与还原系统
0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突
Flutter编译报错 version of NDK matched the requested version 21.0.6113669. Versions available locally: 2
按二进制数中1的个数分类
如何组装一个注册中心?
Linkedblockingqueue of novice source code