当前位置: 首页 > news >正文

Pytest自动化测试框架:mark用法---测试用例分组执行

pytest中的mark:

  mark主要用于在测试用例/测试类中给用例打标记(只能使用已注册的标记名),实现测试分组功能,并能和其它插件配合设置测试方法执行顺序等。

如下图,现在需要只执行红色部分的测试方法,其它方法不执行:

设置步骤如下:

1、注册标签名,通过pytest.ini配置文件注册;
2、在测试用例的前面加上:@pytest.mark.已注册标签名
3、运行时,根据用例标签过滤(-m标签名)


通过mark分组执行的用例:

1、在项目下新建一个pytest.ini的配置文件;如下图:

 2、在用例里面添加@pytest.mark.标签名;如下代码:

代码示例:

test_demo_mark_01.py文件

import pytestclass TestDemo01:def test_case_01(self):print('exec TestDemo01 test_case_01',end=' ')assert True@pytest.mark.system_testdef test_case_02(self):print('exec TestDemo01 test_case_02',end=' ')assert True

test_demo_mark_02.py文件

import pytestclass TestDemo02:@pytest.mark.login_module@pytest.mark.system_testdef test_case_01(self):print('exec TestDemo02 test_case_01',end=' ')assert Truedef test_case_02(self):print('exec TestDemo02 test_case_02',end=' ')assert True

test_demo_mark_03.py文件

import pytestclass TestDemo03:@pytest.mark.smoke_test@pytest.mark.login_moduledef test_case_01(self):print('exec TestDemo03 test_case_01',end=' ')assert Truedef test_case_02(self):print('exec TestDemo03 test_case_02',end=' ')assert True

3、在run_case.py文件中执行pytest.main(['-s','-v','-m 标签名')

代码示例:

import pytestpytest.main(['-s','-v','-m smoke_test'])                    # 只执行smoke_test分组下的用例
# pytest.main(['-s','-v','-m system_test or login_module'])   # 两个标签的用例都执行
# pytest.main(['-s','-v','-m system_test and login_module'])  # 包含两个标签的用例才执行
# pytest.main(['-s','-v','-m not login_module'])                # 除了该标签之外,其他用例都执行

执行效果:

这可能是B站最详细的pytest自动化测试框架教程,整整100小时,全程实战!!!

http://www.lryc.cn/news/239403.html

相关文章:

  • 【TCP连接的状态】
  • Node.js入门指南(一)
  • 使用Grpc实现高性能PHP RPC服务
  • 二、爬虫-爬取肯德基在北京的店铺地址
  • linux驱动开发.之spi测试工具spidev_test源码(一)
  • 基于材料生成算法优化概率神经网络PNN的分类预测 - 附代码
  • Go——二、变量和数据类型
  • 合并区间问题
  • 2023 年最新 MySQL 数据库 Windows 本地安装、Centos 服务器安装详细教程
  • 每天一道算法题(十)——获取和为k的子数组
  • 2023年亚太杯数学建模思路 - 案例:最短时间生产计划安排
  • 在vscode中使用Latex:TexLive2023
  • Unity开发之C#基础-File文件读取
  • 深度学习之二(前馈神经网络--Feedforward Neural Network)
  • 2023全球边缘计算大会深圳站-核心PPT资料下载
  • 【亚太杯思路助攻】2023年第十三届APMCM亚太地区大学生数学建模竞赛——(文末领取方式)
  • vue开发一、在Vue中引入ElementUI二、在Vue中使用阿里图标库
  • 基于SpringBoot+Mybatis plus+React.js实现条件选择切换搜索功能
  • 【STM32】W25Q64 SPI(串行外设接口)
  • 如何使用Mondo Rescue备份及恢复Linux系统(制作ISO镜像,成功恢复)
  • Java如何获取泛型类型
  • 2023年【起重机械指挥】考试题及起重机械指挥找解析
  • 【前端学java】Java中的接口和枚举概念(7)
  • P8611 [蓝桥杯 2014 省 AB] 蚂蚁感冒(模拟)
  • 边缘计算是如何为元宇宙提供动力的?
  • 优秀智慧园区案例 - 上海世博文化公园智慧园区,先进智慧园区建设方案经验
  • 【DevOps】Git 图文详解(五):远程仓库
  • 如果在手机没有root的情况下完成安卓手机数据恢复
  • C++学习 --stack
  • 简单但好用:4种Selenium截图方法了解一下!