定制自动化pytest框架+allure报告

在自动化测试中,基本都需要使用到pytest框架来管理我们的用例,使用allure框架来生成报告。今天就和大家分享一下这方面的知识,跟着步骤走起来~~~

pytest框架

1、pytest命名规范

pytest测试文件必须以test_开头,或以 _test结尾

测试类必须以Test开头,并且类中不能有init方法

测试方法必须以test开头

断言必须使用assert

2、数据驱动

@pytest.mark.parametrize装饰器可以让测试数据参数化,实现数据驱动,方便代码和测试数据分离

3、多重断言

python 复制代码
pip install pytest-assume

4、生成allure报告

python 复制代码
pip install allure-pytest

allure.zip包解压到某个盘符下即可,并配置环境变量

在cmd命令窗口敲

生成allure报告的命令

5、allure的层级

@allure.epic()第一层 表示项目或应用的范围

@allure.feature()第二层 表示功能或模块

@allure.story()第三层 表示测试主题

@allure.title()第四层 表示具体的测试步骤

6、用例步骤

7、用例的严重等级

severity()

以上就是pytest框架+allure报告具体操作步骤,看完文章就跟着练起来吧!

相关推荐
用户8356290780517 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng89 小时前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi10 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee10 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay10 小时前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤10 小时前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean11 小时前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽12 小时前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户606487671889613 小时前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听13 小时前
RAG深入学习之Chunk
前端·人工智能·python