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://github.com/allure-framework/allure2/releases
- 解压 -> 进入bin目录 -> 运行allure.bat,
- 把bin目录加入PATH环境变量
allure官网 : https://qameta.io/allure-report/
allure文档 : https://docs.qameta.io/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://docs.qameta.io/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 ./report/1/ --clean
allure