pytest 接口测试(六)测试报告--allure报告

allure环境准备

首先用“pip show pytest”查看版本号(我的是4.5.0,且python是3.6),然后以下命令进行安装

pip install pytest==4.5.0 --index-url  https://pypi.douban.com/simple
pip install allure-pytest==2.8.6 --index-url  https://pypi.douban.com/simple

执行完成后,输入:pip show allure-pytest
在这里插入图片描述
allure是一个命令行工具,需要去github上下载最新版下载地址
在这里插入图片描述
下载完成后进行解压
在这里插入图片描述
把bin目录下的allure.bat配置到环境变量
在这里插入图片描述
输入allure,出现以下信息,表示配置成功
在这里插入图片描述

生成allure报告

import allure

@allure.step("操作步骤1的描述")
def setp1():
    print('操作步骤1')
@allure.step("操作步骤2的描述")
def setp2():
    print('操作步骤2')

@allure.feature('测试接口--模块描述')
class Test_01(object):
    @allure.story('测试用例的描述--测试用例1')
    def test_01(self, first):
        '''
        用例详情描述
        :param first: 前置条件
        :return:
        '''
        setp1()
        setp2()
        print('test_01,调用first成功', first)
        assert 1 == 1
    @allure.story('测试用例的描述--测试用例2')
    def test_02(self):
        print('test_02,不需要调用')
    @allure.story('测试用例的描述--测试用例3')
    def test_03(self, first2):
        print('test_03,调用first成功', first2)

在命令行输入:

pytest --alluredir ./report/allure_raw
./report/allure_raw   allure测试报告生成的路径,在当前文件夹下的report文件夹下生成allure_raw原始文件

运行完成后,会在当前路径下生成一个allure_raw,再在cmd命令行启动allure服务渲染allure文件。输入:

allure serve report/allure_raw

allure服务启动成功后,会自动打开浏览器显示报告

在这里插入图片描述
在这里插入图片描述
定制化allure报告

发布了28 篇原创文章 · 获赞 0 · 访问量 385

猜你喜欢

转载自blog.csdn.net/qq_42098424/article/details/103994728