pytest自动化测试指定执行测试用例

1、在控制台执行

打开cmd,进入项目目录

  • 指定执行某个模块 pytest testcases\Logistics\Platform\CarSource\test_CarSourceList.py

  • 指定执行某个目录及其子目录的所有测试文件 pytest testcases\Logistics\Platform\CarSource

  • 指定执行某个模块的某个类的某个测试用例 pytest testcases\Logistics\Platform\Home_page\test_navigation.py::TestNavigation::test_08_navigation

更多用法参考使用参数

2、通过pytest代码执行

直接执行RunTestCase.py【自动查找当前目录下,以test_开头的文件或者以_test结尾的py文件】

法一:args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME]

pytest.main(args) 【 []内的多个参数通过'逗号,'进行分割】

法二:args="pytest -m Navigation"

os.system(args)

  • 指定执行某个目录/某个模块/某个类/某个用例,用::连接 args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-v','testcases\Logistics\Platform\CarSource\\test_CarrierShop.py::TestCarrierShop::test_01_carrierShop']

  • 指定执行多个目录/多个模块/多个类 args = ['--reruns', '1', '--html=./Report/Report.html','-v', 'testcases\Logistics\Platform\CarSource', 'testcases\Logistics\Platform\Login', r'testcases\Logistics\Platform\Home_page\test_navigation.py']

  • **指定关键字匹配来运行测试用例名字子串 (-k )**args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-k','01','testcases\Logistics\Platform\CarSource']

  • 指定执行某个标签 (一次只能指定一个标签)args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-m','CarrierShopTest']

  • 执行返回失败的用例 args =['--reruns', '1', '--html=./Report/Report.html', '-v','--lf']

3、常用参数说明 pytest

**-v:**说明:可以输出用例更加详细的执行信息,比如用例所在的文件及用例名称等

**-S:**说明:输入我们用例中的调式信息,比如print的打印信息等

**-m :**说明:执行特定的测试用例,"标记"

**-k:**说明:执行用例包含"关键字"的用例 ,"关键字"

-q: 说明:简化控制台的输出

--lf:当一次用例执行完成后,如果其中存在失败的测试用例,那么我们可以使用此命令重新运行失败的测试用例

--ff:如果上次测试用例出现失败的用例,当使用--ff后,失败的测试用例会首先执行,剩余的用例也会再次执行一次

正在学习测试的小伙伴可以通过点击下面的小卡片

相关推荐
兴趣使然黄小黄3 小时前
【Pytest】Pytest常用的第三方插件
python·pytest
我的xiaodoujiao5 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 34--基础知识 9--文件上传功能
前端·python·测试工具·ui·pytest
我一定会有钱6 小时前
pytest测试框架基础
python·单元测试·自动化·pytest
我的xiaodoujiao6 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 35--二次封装MySQL数据库连接操作
python·学习·测试工具·pytest
给你一页白纸1 天前
Pytest 测试用例自动生成:接口自动化进阶实践
python·pytest·接口自动化
工会主席-阿冰1 天前
使用pytest-selenium插件,ui自动化示例
selenium·pytest
工会主席-阿冰1 天前
pytest,ui自动化示例
pytest·ui自动化
Wpa.wk1 天前
自动化测试-自动化测试用例流程设计
运维·经验分享·自动化·测试用例·测试流程·测试流程设计
卓码软件测评2 天前
第三方APP软件测试机构:【Gatling如何测试移动应用后端API移动网络特性和用户行为模拟】
网络·测试工具·单元测试·测试用例
qq_白羊座3 天前
测试用例(设计、实现、执行)分析与策略制定
测试用例