【pytest-20】allure-pytest生成测试报告

前言

前面说了有pytest-html自带的测试报告,简洁大方,对比之下,pytest-allure是一份显得够高端,大气,上档次的测试报告。

  • 是一个report框架,可以基于一些测试框架生成测试报告;
  • 生成的报告样式简洁美观,同时又支持中文
  • 还支持使用Jenkins工具持续集成,整套环境搭建下来以后,使用起来非常方便。

安装

pip install allure-pytest

使用

这里沿用上篇的pytest-19

#demo_pyetst/conftest.py
import pytest
@pytest.fixture(scope="session")
def openBroswer():
    print("打开浏览器")

#demo_pyetst/toutiao/conftest.py
import pytest
@pytest.fixture(scope="session")
def search_data():
    print("搜索今日头条")

#demo_pyetst/toutiao/test_b.py
import pytest
import time

def test_01(openBroswer,search_data):
    print("toutiao用例1")
    time.sleep(1)


def test_02(openBroswer,search_data):
    print("toutiao用例2")
    time.sleep(1)


def test_03(openBroswer,search_data):
    print("toutiao用例3")
    time.sleep(1)

if __name__ == '__main__':
    pytest.main(["-s","test_b.py"])

#demo_pytest/vx/conftest.py
import pytest
@pytest.fixture(scope="function")
def search_vx():
    print("搜索微信")

#demo_pytest/vx/test_a.py
import pytest
import time

def test_1(openBroswer,search_vx):
    print("vx搜索用例1")
    time.sleep(1)

def test_2(openBroswer,search_vx):
    print("vx添加用例2")
    time.sleep(1)

if __name__ == '__main__':
    pytest.main(["-s","test_a.py"])

#pytest_demo/vx/test_c.py
import pytest
import time

def test_3(openBroswer, search_vx):
    print("vx测试用例3")
    time.sleep(1)

def test_4(openBroswer, search_vx):
    print("vx测试用例4")
    time.sleep(1)

def test_5(openBroswer, search_vx):
    print("vx测试用例5")
    time.sleep(1)

if __name__ == "__main__":
    pytest.main(["-s", "test_c.py"])
View Code

运行用例

pytest --alluredir ./report/allure_raw

执行完成后,在当前目录下,report目录会生成一个allure_raw的原始文件,这个只是测试报告的原始文件,不能打开成html的报告

 打开html的报告需要启动allure服务,启动命令如下

allure serve report/allure_raw

 

安装allure命令行工具

allure是一个命令行工具,需要去github上下载最新版https://github.com/allure-framework/allure2/releases

下载到本地并解压,把bin目录添加到环境变量Path下。

再次执行,启动服务,直接用默认浏览器打开。

allure serve report/allure_raw

 查看报告

 查看测试套件,文件名-类名-测试用例

 

posted @ 2020-12-17 14:44  做一只热爱生活的小透明  阅读(94)  评论(0)    收藏  举报