前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Pytest篇】Allure生成漂亮的HTML图形化测试报告(一))

【Pytest篇】Allure生成漂亮的HTML图形化测试报告(一))

作者头像
王大力测试进阶之路
发布2019-10-25 18:04:44
4.2K0
发布2019-10-25 18:04:44
举报
文章被收录于专栏:橙子探索测试橙子探索测试

Python Pytest装饰器@pytest.mark.parametrize详解

一、Allure测试报告介绍

Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架。它支持绝大多数测试框架, 例如TestNG、Pytest、JUint等。它简单易用,易于集成。

二、Pytest框架集成Allure

Pytest是Python的单元测试框架,非常方便和易用。强烈推荐对于用Python进行测试工作的小伙伴使用这个测试框架,相比与Python自带的UnitTest好用太多太多。后面我将用一整篇文章介绍Pytest测试框架。今天我们主要是介绍如何将测试报告生成工具Allure集成到Pytest中。

三、安装allure-pytest

pip install allure-pytest

四、下载allure-2.7.0

https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/allure-2.7.0.zip

下载后解压,放在某个位置(建议放在C:\Program Files\Python35\Lib\site-packages下)

五、配置环境变量

环境变量path中加上解压好的文件夹下的bin目录下的allure.bat文件的路径(这里是:C:\Program Files\Python35\Lib\site-packages\allure-2.7.0\bin)

六、在cmd下生成测试报告

在test\report\result下生成json测试报告

C:\Users\wangli\PycharmProjects\Test\test

pytest -s -q --alluredir report/result test03.py

report目录下,转为html格式的Allure测试报告

cd C:\Users\wangli\PycharmProjects\Test\test\report

allure generate ./result/ -o ./report/html --clean

七、pycharm生成测试报告

代码语言:javascript
复制
def test1():
    assert "18221124104" == "18221124104"
def test2():
    assert 1==2
if __name__=="__main__":
    #pytest.main(["-v","test03.py",'--alluredir','result'])
    #生成测试报告json
    pytest.main(["-s", "-q", '--alluredir', 'report/result', 'test03.py'])
    # #os.system("allure" "generate","./result/","-o","./report/html")
    #将测试报告转为html格式
    split='allure '+'generate '+'./report/result '+'-o '+'./report/html '+'--clean'
    os.system('cd C:/Users/wangli/PycharmProjects/Test/test/report')
    os.system(split)
    print(split)
    
    
    
    "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/Test/test/test03.py
.F
================================== FAILURES ===================================
____________________________________ test2 ____________________________________

    def test2():
>       assert 1==2
E       AssertionError

test03.py:90: AssertionError
1 failed, 1 passed in 0.23s
Report successfully generated to .\report\html
allure generate ./report/result -o ./report/html --clean

Process finished with exit code 0

生成测试报告json格式

json格式测试报告转为html格式的Allure测试报告

八、Allure测试报告视图展示,是不是看起来很漂亮

打开html测试报告file:///C:/Users/wangli/PycharmProjects/Test/test/report/html/index.html

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-10-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 橙子探索测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Python Pytest装饰器@pytest.mark.parametrize详解
  • 一、Allure测试报告介绍
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档