当前位置:网站首页>单元测试界的高富帅,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
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
边栏推荐
- Go从入门到实战——channel的关闭和广播(笔记)
- 创建对象时JVM内存结构
- GBase 8a的create database 会被查询耗时很长怀疑卡住的现象分析
- GBase 8a OLAP分析函数 cume_dist的使用样例
- Go从入门到实战——Panic和recover(笔记)
- ABC-Teleporter Setting-(思维+最短路)
- [LeetCode]161. 相隔为 1 的编辑距离
- 空指针异常
- Gbase 8A method for reducing the impact on the system by controlling resource usage through concurrency during node replacement of V8 version
- String类的常用方法
猜你喜欢
随机推荐
matlab查找某一行或者某一列在矩阵中的位置
[LeetCode]100. Same tree
Knowledge sorting of exception handling
Oracle migration MySQL unique index case insensitive don't be afraid
[LeetCode]515. Find the maximum value in each tree row
【MySQL】数据库函数通关教程下篇(窗口函数专题)
MYSQL和MongoDB的分析
[LeetCode]515. 在每个树行中找最大值
VMware virtual machine PE startup
神奇的POI读取excel模板文件报错
[LeetCode]508. 出現次數最多的子樹元素和
空指针异常
Go从入门到实战——多态(笔记)
快递e栈——数组篇小型项目
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Example of using gbase 8A OLAP function group by grouping sets
Process control task
[LeetCode]100. 相同的树
Go从入门到实战——协程机制(笔记)
Special tutorial - Captain selection game









