定制自动化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报告具体操作步骤,看完文章就跟着练起来吧!

相关推荐
AI探索者8 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者8 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh10 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅10 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽11 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时15 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿17 小时前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi1 天前
Chapter 2 - Python中的变量和简单的数据类型
python