Pytest教程__定制allure报告(12)

定制报告需要先导入allure模块,再使用以下装饰器方法:

  • feature: 标注主要功能模块。
  • story: 标注feature功能模块下的分支功能。
  • description:在报告中显示用例描述。
  • step: 标注测试用例步骤。
  • issue && testcase:标注用例关联的链接。
  • attach: 添加一些附加内容到测试报告中。
  • severity: 标注测试用例的重要级别,包含blocker, critical, normal, minor, trivial 几个不同的等级。

feature && story

主要用于为用例分层级

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    def test_001(self):
        print("\n填写信息")
        print("\n点击提交")

    @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
    def test_002(self):
        print("\n点击提交")

报告样式如下:

description

用于在报告中增加用例描述信息,除了这个方法外,还可以在方法下使用3个引号的方式增加用例描述信息。

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    @allure.description("用例描述...这样...那样...")
    def test_001(self):
        print("\n填写信息")
        print("\n点击提交")

    @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
    def test_002(self):
        """用例描述...也可以...这样...那样"""
        print("\n点击提交")

报告样式如下:

step

在报告中增加测试步骤的显示。

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    @allure.description("用例描述...这样...那样...")
    def test_001(self):
        with allure.step("1、填写信息"):
            print("\n填写信息")
            assert 1 == 1
        with allure.step("2、点击提交"):
            print("\n点击提交")
            assert 2 == 1

    @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
    def test_002(self):
        """用例描述...也可以...这样...那样"""
        print("\n点击提交")

报告样式如下:

issue && testcase

issue与testcase用于在报告中增加关联链接,用法基本一样,第1个参数为关联的url地址,第2个为缺省参数,作用是为地址的别名。

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    @allure.description("用例描述...这样...那样...")
    @allure.issue("http://www.baidu.com")
    @allure.testcase("http://www.baidu.com", "百度一下")
    def test_001(self):
        with allure.step("1、填写信息"):
            print("\n填写信息")
            assert 1 == 1
        with allure.step("2、点击提交"):
            print("\n点击提交")
            assert 2 == 1

    @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
    def test_002(self):
        """用例描述...也可以...这样...那样"""
        print("\n点击提交")

报告样式如下:

attach

在报告中添加一些附加内容,内容可以为文本信息、图片、文件等。

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    @allure.description("用例描述...这样...那样...")
    @allure.issue("http://www.baidu.com")
    @allure.testcase("http://www.baidu.com", "百度一下")
    def test_001(self):
        with allure.step("1、填写信息"):
            print("\n填写信息")
            assert 1 == 1
        with allure.step("2、点击提交"):
            print("\n点击提交")

        # attach 添加文本信息
        allure.attach("文本信息标注信息...", "别名")
        # attach 可以添加图片
        allure.attach.file(r"D:\Users\User\Desktop\图片管理\60-60.jpg", "图片", attachment_type=allure.attachment_type.JPG)
        # attach 可以添加html文件
        allure.attach.file(r"D:\Users\User\Desktop\图片管理\test.html", "html文件", attachment_type=allure.attachment_type.HTML)

    @allure.story("不输入任何信息,点击提交,预期提示填写必填项")
    def test_002(self):
        """用例描述...也可以...这样...那样"""
        print("\n点击提交")

报告样式如下:

severity

为测试用例的划分重要级别,包含blocker, critical, normal, minor, trivial 5个不同的等级。默认是normal级别。

import allure


@allure.feature("评论模块")
class TestComment:

    @allure.story("填写所有信息,点击提交,预期评论成功")
    @allure.description("用例描述...这样...那样...")
    @allure.issue("http://www.baidu.com")
    @allure.testcase("http://www.baidu.com", "百度一下")
    def test_001(self):
        with allure.step("1、填写信息"):
            print("\n填写信息")
            assert 1 == 1
        with allure.step("2、点击提交"):
            print("\n点击提交")

        # attach 添加文本信息
        allure.attach("文本信息标注信息...", "别名")
        # attach 可以添加图片
        allure.attach.file(r"D:\Users\User\Desktop\图片管理\60-60.jpg", "图片", attachment_type=allure.attachment_type.JPG)
        # attach 可以添加html文件
        allure.attach.file(r"D:\Users\User\Desktop\图片管理\test.html", "html文件", attachment_type=allure.attachment_type.HTML)

    @allure.severity("blocker")
    def test_002(self):
        pass

    @allure.severity("critical")
    def test_003(self):
        pass

    @allure.severity("minor")
    def test_004(self):
        assert 1 == 2

报告样式如下:

环境配置信息

在概览中查看环境配置默认是没有的。

若要在报告中增加环境信息需要在第一步生成的json文件中,增加一个environment.properties文件,文件内容如下样式:

systemVersion=win10
pythonVersion=3.8.5
allureVersion=2.13.9
baseUrl=http://192.168.1.x:8080
projectName=test

然后再执行并生成报告,报告样式如下:

在allure 1.X的中,可以通过一个以test开头的py文件来配置,该方法在 2.X已弃用,仅供了解:

报告样式如下:

-事必有法,然后有成- 最后祝大家早日达到测试的天花板!



以下是我收集到的比较好的学习教程资源,虽然不是什么很值钱的东西,如果你刚好需要,可以留言【777】直接拿走就好了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值