欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > Shell 脚本与 Pytest 结合:交替运行 Pytest 的两个测试方法

Shell 脚本与 Pytest 结合:交替运行 Pytest 的两个测试方法

2025/2/24 14:36:41 来源:https://blog.csdn.net/zhang_jiamin/article/details/145003560  浏览:    关键词:Shell 脚本与 Pytest 结合:交替运行 Pytest 的两个测试方法

有这样一个情况,在test_user_center.py文件中有两个测试方法,test_login和test_logout,

如果在终端这样指定命令:

pytest -q -s -ra --count=500 test_user_center.py --alluredir=./report/login_and_logout/resource | tee pytest_summary.log,

那么会先执行500遍test_login之后再执行500遍test_logout,test_login 和 test_logout 测试方法并不会以交替顺序执行(即 test_login -> test_logout -> test_login -> test_logout,重复执行 500 次)。

那么如何实现交替执行两个测试方法的预期呢?这里介绍一个使用shell解决的方法:

1、直接执行,在终端中运行:

for i in {1..500}; do pytest -q -s -ra test_user_center.py --alluredir=./report/login_and_logout/resource | tee pytest_summary.log; done | tee pytest_summary.log

2、保存为 Shell 脚本,将代码保存为文件,比如 run_tests.sh: 

#!/bin/bash
for i in {1..500}
dopytest -q -s -ra test_user_center.py --alluredir=./report/login_and_logout/resource | tee pytest_summary.log
done | tee pytest_summary.log

然后赋予可执行权限:

chmod +x run_tests.sh

最后运行:

./run_tests.sh

有兴趣的小伙伴们可以尝试一下这种方法,当然还有别的方法,后面慢慢讲。

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词