当前位置:网站首页>单元测试界的高富帅,Pytest框架,手把手教学,以后测试报告就这么做~
单元测试界的高富帅,Pytest框架,手把手教学,以后测试报告就这么做~
2022-06-27 19:36:00 【软件测试呀】
一、生成 HTML 报告
pytest 生成 HTML 的插件有很多,比如 pytest-html,pytest-testreport 等等,下面就给大家介绍如何使用 pytest-testreport 这个插件来生成 HTML 测试报告。
1.1、安装插件
pip install pytest-testreport
注意点:如果安装了 pytest-html 这个插件请先卸载,不然有可能会有冲突
1.2、插件的使用介绍
在使用 pytest 运行测试时,如果要使用 pytest-testreport 生成测试报告, 运行测试时加上参数 --report 指定报告文件名,即可实现。
其他运行参数:
–title :指定报告标题
–tester :指定报告中的测试者
–desc :指定报告中的项目描述
–template :指定报告模板样式(1 or 2)
命令行执行:
pytest --report=musen.html --title=测试报告 --tester=木森 --desc=项目描述 --template=2
代码中使用 pytest.main 执行
import pytest
生成的报告样式如下
样式一
样式二
关于 HTML 格式的报告生成就给大家介绍到这里,接下来和大家讲讲怎么集成 allure 报告
二、集成 Allure 报告
如果要在 pytest 中集成 allure 报告,首先得下载 allure,并配置好环境
2.1、allure 环境配置
一、下载 allure:
地址:https://github.com/allure-framework/allure2/releases
下载之后并解压
二、环境变量配置
将 allure 解压之后的 allure 路径的 bin 目录路径放到环境变量当中
三、安装 allure 的 pytest 插件
pip install allure-pytest
2.2、生成 allure 报告
安装配置好 allure 环境之后,在使用 pytest 执行用例时,就可以通过 allure 插件的参数来指定生成 allure 来报告了。
运行参数:
--alluredir :指定 allure 报告保存的路径
命令行运行
pytest --alluredir=reports
代码中使用 pytest.main 执行
import pytest
2.3、启动 allure 服务
在命令终端输入如下命令,启动 allure 服务
# 命令:allure serve 生成的报告路径
执行上述命令,allure 服务启动之后会自动在打开浏览器,显示 allure 的服务页面
2.4、allure 内置常用的方法
添加错误截图
allure.attach
def error_save_screenshot(driver,file_path, desc):
添加报告中的用例名称
allure.title
import allure
参数化的用例中动态设置用例名称
allure.dynamic.title
# 用例数据
添加报告中的功能描述
allure.story
@allure.story('登录功能')
添加报告中套件名称
allure.suite
@allure.suite('登录测试套件')
房子要一层一层盖,知识要一点一点学。大家在学习过程中要好基础,多上手实操,话不多说,这里狠狠上一次干货!我熬夜整理好的各阶段(功能、接口、自动化、性能、测开)技能学习资料+实操讲解,非常适合私下里学习,比找资料自学高效多了,分享给你们。
领取关 w/x/g/z/h:软件测试小dao
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
边栏推荐
- The difference between scrum and Kanban
- [LeetCode]161. 相隔为 1 的编辑距离
- Stm32f107+lan8720a use stm32subemx to configure network connection +tcp master-slave +udp app
- Go from introduction to practice - Interface (notes)
- 软件测试自动化测试之——接口测试从入门到精通,每天学习一点点
- Tiktok's interest in e-commerce has hit the traffic ceiling?
- String类的常用方法
- Go从入门到实战——行为的定义和实现(笔记)
- oracle迁移mysql唯一索引大小写不区分别怕
- Go from introduction to actual combat - panic and recover (notes)
猜你喜欢

I think I should start writing my own blog.

关于异常处理的知识整理

Go从入门到实战——channel的关闭和广播(笔记)

图解基于AQS队列实现的CountDownLatch和CyclicBarrier

win11桌面出现“了解此图片”如何删除

Null pointer exception

Go from introduction to actual combat - context and task cancellation (notes)

Go从入门到实战——依赖管理(笔记)

CORBA 架构体系指南(通用对象请求代理体系架构)

Interval DP of Changyou dynamic programming
随机推荐
win11桌面出现“了解此图片”如何删除
专题教程——选队长游戏
关于异常处理的知识整理
数组作业题
[LeetCode]161. 相隔为 1 的编辑距离
Go从入门到实战——CSP并发机制(笔记)
富文本 考试 填空题
流程控制任务
∫(0→1) ln(1+x) / (x ² + 1) dx
Have time to look at ognl expressions
ABC-Teleporter Setting-(思维+最短路)
Go从入门到实战——仅执行一次(笔记)
[LeetCode]572. 另一棵树的子树
集合代码练习
Go从入门到实战——所有任务完成(笔记)
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Quick excel export according to customized excel Title Template
我想我要开始写我自己的博客了。
Open source technology exchange - Introduction to Chengying, a one-stop fully automated operation and maintenance manager
动态刷新mapper看过来