当前位置:网站首页>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报告用的
边栏推荐
猜你喜欢
![[paper after dinner] deep mining external perfect data for chestx ray disease screening](/img/d6/41c75d292c26b2e7e116767a51eb5e.png)
[paper after dinner] deep mining external perfect data for chestx ray disease screening

菜鸟看源码之ArrayDeque

Wechat official account message notice "errCode": 40164, "errmsg": "invalid IP

0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突

WIRESHARK基础教程以太帧的分析。

RT thread learning notes (III) -- building a compilation environment with scons

如何组装一个注册中心?
![[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
随机推荐
Capture ZABBIX performance monitoring chart with selenium
35. 搜索插入位置
flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
BigDecimal's addition, subtraction, multiplication and division, size comparison, rounding up and down, and BigDecimal's set accumulation, judge whether BigDecimal has decimal
Pengge C language sixth class
@The difference and use of jsonformat and @datetimeformat
MFC多线程的简单使用
Definition and use of C language namespace
Bash shell learning notes (I)
Stringing of macro parameters and connection of macro parameters in C language
Sword finger offer (53): a string representing a numeric value
1748.唯一元素的和
Pengge C language - minesweeping 2021-08-16
Tutorial of putty
Sql Server之查询总结
PLC与伺服电机连接
Successfully transplanted stemwin v5.22 on Shenzhou IV development board
How to assemble a registry?
Flutter 防止科学计数并去除尾数无效0
Flutter集成极光推送