pytest学习系列_pytest-html插件之生成HTML测试报告
一、前言
在我们做自动化的时候,写好用例是一方面,还有比较重要的是执行结果需要可视化,pytest-html插件就提供了一个相对比较好的解决方案
二、安装
pipi install pytest-html
三、使用方法
1、代码示例
#!/usr/bin/python3 # -*- coding: UTF-8 -*- """ @author:durant.zeng @Description:描述 @file:test_rerun.py @time:2020/12/11 """ import requests def test_taobao1(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.30) print(r.elapsed.total_seconds()) def test_taobao2(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.30) print(r.elapsed.total_seconds()) def test_taobao3(): url = "https://taobao.com" r = requests.post(url=url,timeout=0.09) print(r.elapsed.total_seconds())
2、执行命令
pytest --reruns 2 --html=report.html
与失败重试参数结合起来
(CloudStorage) D:\learn\IOT\CloudStorage\unit>pytest --reruns 2 --html=report.html Test session starts (platform: win32, Python 3.7.2, pytest 6.0.1, pytest-sugar 0.9.4) rootdir: D:\learn\IOT\CloudStorage\unit plugins: Faker-4.1.3, html-3.1.0, metadata-1.11.0, rerunfailures-9.1.1, sugar-0.9.4, tavern-1.11.1, allure-pytest-2.8.18, base-url-1.4.2, forked-1.3.0, xdis t-2.1.0 collecting ... test_rerun.py ✓ 33% ███▍ test_rerun.py ✓✓ 67% ████ test_rerun.py ✓✓RR✓ 100% ███ ███████ ==================================================================== warnings summary ===================================================================== c:\users\durant.zeng\.virtualenvs\cloudstorage\lib\site-packages\pykwalify\core.py:7 c:\users\durant.zeng\.virtualenvs\cloudstorage\lib\site-packages\pykwalify\core.py:7: DeprecationWarning: the imp module is deprecated in favour of import lib; see the module's documentation for alternative uses import imp -- Docs: https://docs.pytest.org/en/stable/warnings.html ----------------------------------------- generated html file: file://D:\learn\IOT\CloudStorage\unit\report.html ------------------------------------------ Results (2.98s): 6 passed 2 rerun
3、报告展示,在当前目录生成报告
4、指定报告路径,比如是工程目录report
pytest --html=./report/report.html
知道、想到、做到、得到
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)