allure插件安装
Allure是一个独立的报告插件,生成美观易读的报告。
目前支持语言:Java, PHP, Ruby, Python, Scala, C#。
Allure工具安装
https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
添加 安装路径\allure-2.13.2\bin至环境变量PATH
完成以上步骤之后,命令行测试一下是否安装成功 :allure --version
allure-pytest安装
为了解决安装allure后执行命令后报错module 'pytest' has no attribute 'allure'的问题,发现之前安装了pytest-allure-adaptor
。
如果存在安装过的pytest-allure-adaptor
插件,先卸载:pip uninstall pytest-allure-adaptor
重新安装allure-pytest:pip install allure-pytest
如果上述方法安装不了,则改用豆瓣进行安装,格式为:pip install 库名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Allure帮助文档: https://docs.qameta.io/allure/#_about
生成Allure报告: 命令行参数:pytest --alluredir report # 在执行命令目录生成report文件夹,文件夹下包含json文件
在包里新建配置文件pytest.ini:
1 [pytest] 2 ;--html=./report.html 3 ;删除原生html,增加Allure 4 addopts = -s --alluredir report 5 # 测试路径 6 testpaths = ./Test 7 # 测试文件名 8 python_files = test_*.py 9 # 测试类名 10 python_classes = Test_* 11 # 测试的方法名 12 python_functions = test_*
新建test_001.py:
1 import allure
2 import pytest
3
4
5 class Test_Abc:
6 @allure.step(title='第一个测试.')
7 def test_abc_001(self):
8 assert 1
9
10 @pytest.mark.parametrize('a', [0, 1, 2])
11 @allure.severity(allure.severity_level.CRITICAL) # 严重级别(BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL)
12 @allure.step(title='第二个测试.')
13 def test_abc_002(self, a):
14 allure.attach('描述', '我是测试步骤001的描述~~~')
15 assert a != 2
16
17
18 if __name__ == '__main__':
19 pytest.main("-s --alluredir report test_001.py")
操作步骤:
1.命令行进入pytest.ini所在目录
2.输入命令:pytest
执行结果:pytest.ini所在目录生成report文件夹,文件夹下生成一个或几个json文件
json转html:
1.进入report上级目录执行命令:allure generate report/ -o report/html
2.report目录下会生成index.html文件,即为可视化报告,用浏览器打开
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)