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

本文介绍了如何将Allure测试报告框架集成到Pytest中,详细阐述了安装allure-pytest,配置环境变量,通过cmd和PyCharm生成测试报告的步骤,并展示了Allure测试报告的美观视图。
摘要由CSDN通过智能技术生成

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下)

5a91c0ba597cbf5c814422730f6f3546.png

五、配置环境变量

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

4f62f66a06dd9d1ed88073641159ee65.png

六、在cmd下生成测试报告

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

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

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

7b67e7eed3813b9bd98a9840a510c893.png

5f5258e508811eecdf7fa7c7ae02916e.png

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

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

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

24d7d6ae765fa1c78537bb30ce2d5a91.png

e008c233f26ebcdf088ce8ded9fd7a3f.png

七、pycharm生成测试报告

def test1():    assert "18221124104" == "18221124104"def test2():    assert 1==2if __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==2E       AssertionErrortest03.py:90: AssertionError1 failed, 1 passed in 0.23sReport successfully generated to .\report\htmlallure generate ./report/result -o ./report/html --cleanProcess finished with exit code 0

生成测试报告json格式

f86b88e0e040736b0d062d2126e59038.png

30d4b20f327803aac85f53901e06a063.png

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

6ff237fb7a5854f38f4d533bd0fa7eb5.png

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

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

43386cf5e3b5454a47c73f7299aa4d39.png

99ab47c7baee85acb1b2b9abf2c1d004.png

ca03d77b96449f9a5d0fa71300fb4c4d.png

179d5470e370047679cea0fd5abf07a8.png

3cbdea6a422e60fe778fab4c6de7359f.png

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值