js网站源码已到期,wordpress 星星评分,dedecms 旅游网站模板下载,浙江金顶建设公司网站1、Pytest跳过测试用例
自动化测试执行过程中#xff0c;我们常常出现这种情况#xff1a;因为功能阻塞#xff0c;未实现或者环境有问题等等原因#xff0c;一些用例执行不了#xff0c; 如果我们注释掉或删除掉这些测试用例#xff0c;后面可能还要进行恢复操作#…
1、Pytest跳过测试用例
自动化测试执行过程中我们常常出现这种情况因为功能阻塞未实现或者环境有问题等等原因一些用例执行不了 如果我们注释掉或删除掉这些测试用例后面可能还要进行恢复操作这时我们就可以配置跳过这些用例。 Pytest测试框架中存在两个跳过测试的方法skip和skipif 。
1无条件跳过skip
skip方法为无条件跳过测试用例。
使用方法pytest.mark.skip标记在需要跳过的测试用例上。
2有条件跳过skipif
skipif方法为有条件跳过测试用例条件为真跳过。
使用方法pytest.mark.skipif(condition跳过的条件, reason跳过的原因)
标记在需要符合条件跳过的测试用例上。
参数condition跳过的条件为True则跳过测试为False则继续执行测试默认为True。参数reason标注跳过的原因必填参数。
3练习 1.学习目标掌握pytest中跳过测试方法
2.操作步骤skipif(condition判断条件,reason跳过原因)使用时放置在需要跳过的用例之前pytest.mark.skipif(条件,原因) # 当条件为真,跳过执行
3.需求# 导入pytest
import pytest# 编写测试用例
def login_data():return jerry, 123456# 无条件跳过
pytest.mark.skip
def test_register():注册用例print(注册步骤)assert False# 当条件为真,跳过测试
pytest.mark.skipif(login_data()[0] jerry, reasonjerry用户不存在)
def test_login():不记住密码登录username login_data()[0]password login_data()[1]print(f输入用户名{username})print(f输入密码{password})print(点击登录按钮)assert username jerrydef test_shopping():购物下单print(购物流程)assert Trueif __name__ __main__:pytest.main()
执行结果跳过一个用例 1通过2跳过test_pytest_01.py::test_register
test_pytest_01.py::test_login
test_pytest_01.py::test_shopping 1 passed, 2 skipped in 0.04s Process finished with exit code 0
SKIPPED (unconditional skip)
Skipped: unconditional skip
SKIPPED (jerry用户不存在)
Skipped: jerry用户不存在
购物流程
PASSED# 注跳过的用例测试结果标识为s2、Pytest失败重试
Pytest失败重试就是在执行一次测试脚本时如果一个测试用例执行结果失败了则重新执行该测试用例。
现在我也找了很多测试的朋友做了一个分享技术的交流群共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源没人解答问题坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化性能安全测试开发等等方面有一定建树的技术大牛
分享他们的经验还会分享很多直播讲座和技术沙龙
可以免费学习划重点开源的
qq群号110685036【暗号csdn999】 前提
Pytest测试框架失败重试需要下载pytest-rerunfailures插件。
安装方式pip install pytest-rerunfailures
Pytest实现失败重试的方式
方式一在命令行或者main()函数中使用
pytest.main([-vs,test_a.py,--reruns2])这种方式没有实现成功可能自己环境的问题
或者
pytest -vs ./test_a.py --reruns 2 --reruns-delay 2可以
表示失败重试2次在每次重试前会等到2秒。 说明 reruns为重跑次数reruns_delay为间隔时间单位s 方式二在pytest.ini配置文件中使用推荐
在pytest.ini配置文件中addopts添加reruns重试参数
[pytest]
addopts -s --reruns 2 --reruns-delay 2
testpaths scripts
python_files test_01.py
python_classes Test*
python_functions test*示例使用第二种方式 1.学习目标掌握pytest中用例失败重试方法
2.操作步骤2.1 安装 pytest-rerunfailurespip install pytest-rerunfailures2.2 使用 在pytest.ini文件中,添加一个命令行参数 --reruns n # n表示重试次数
3.需求# 1.导入pytest
import pytest# 2.编写测试用例
pytest.mark.run(order2)
def test_login():登录用例print(登录步骤)assert abcd in abcdefgpytest.mark.run(order1)
def test_register():注册用例print(注册步骤)assert Falsepytest.mark.run(order4)
def test_shopping():购物下单print(购物流程)assert Truepytest.mark.run(order3)
def test_cart():购物车用例print(购物车流程)assert Trueif __name__ __main__:pytest.main([-vs, test_01.py, --reruns2])# pytest ./pytest_demo/test_01.py --reruns 10 --reruns-delay 1
#执行结果注意有两个2 rerun1 failed, 3 passed, 2 rerun in 0.09s test_01.py::test_register 注册步骤
RERUN
test_01.py::test_register 注册步骤
RERUN
test_01.py::test_register 注册步骤
FAILED
pytest_demo\test_01.py:20 (test_register)
pytest.mark.run(order1)def test_register():注册用例print(注册步骤)assert False
E assert Falsetest_01.py:25: AssertionError
登录步骤
PASSED购物车流程
PASSED购物流程
PASSED注意如果设置失败重试5次在重试的过程中成功了就不用全部跑完5次重试这里需要注意一下。 END今天的分享就到此结束了点赞关注不迷路