allure-pytest,生成测试报告

1、安装 allure-pytest

pip install allure-pytest

2、pytest.ini 添加配置

--alluredir=report/allure #指定生成文件目录

--clean-alluredir   #每次运行时清除上次运行生成的文件

(也可以不修改该配置文件,直接执行步骤3时 pytest 后加上对应参数。但将pytest相关参数写在一个配置文件,执行时只输入pytest,这样更方便些。)

3、执行pytest,此时 report/allure中生成相关文件

4、执行 allure serve report/allure,此时会生成html报告

5、allure装饰器,优化报告

allure 装饰器

使用方法参数值参数说明
@allure.epic()epic描述敏捷里面的概念,定义史诗,往下是feature
@allure.feature()模块名称功能点的描述,往下是story
@allure.story()用户故事用户故事,往下是title
@allure.title(用例的标题)用例的标题重命名html报告名称
@allure.testcase()测试用例的链接地址对应功能测试用例系统里面的case
@allure.issue()缺陷对应缺陷管理系统里面的链接
@allure.description()用例描述测试用例的描述
@allure.step()操作步骤测试用例的步骤
@allure.severity()用例等级blocker,critical,normal,minor,trivial
@allure.link()链接定义一个链接,在测试报告展现
@allure.attachment()附件报告添加附件

测试案例

import pytest
import allure

@pytest.fixture(scope="session")
def login_fixture():
    print("前置条件:登录")


@allure.step("步骤1")
def step_1():
    print("操作步骤---------------1")


@allure.step("步骤2")
def step_2():
    print("操作步骤---------------2")


@allure.step("步骤3")
def step_3():
    print("操作步骤---------------3")


@allure.epic("epic对大Story的一个描述性标签")
@allure.feature("测试模块")
class TestDemoAllure():

    @allure.testcase("http://49.235.x.x:8080/zentao/testcase-view-6-1.html")
    @allure.issue("http://49.235.x.x:8080/zentao/bug-view-1.html")
    @allure.title("用例的标题")
    @allure.story("用户故事:1")
    @allure.severity("critical")
    def test_case_1(self, login_fixture):
        '''case description:作者:上海-悠悠 qq交流群:874033608
        1.点文章分类导航标签 -跳转编辑页面
        2.编辑页面输入,分类名称,如:上海-悠悠-可以输入
        3.点保存按钮保存成功
        '''
        step_1()
        step_2()

    @allure.story("用户故事:2")
    def test_case_2(self, login_fixture):
        print("测试用例1")
        step_1()
        step_3()


@allure.epic("epic对大Story的一个描述性标签")
@allure.feature("模块2")
class TestDemo2():


    @allure.story("用户故事:3")
    def test_case_3(self, login_fixture):
        print("测试用例1")
        step_1()


    @allure.story("用户故事:4")
    def test_case_4(self, login_fixture):
        print("测试用例1")
        step_3()

报告展示

6、allure.attach

作用:支持显示许多不同类型的附件

语法: allure.attach(body, name, attachment_type, extension) 

参数列表

  • body:要显示的内容(附件)
  • name:附件名字
  • attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
  • extension:附件的扩展名(比较少用)

allure.attachment_type提供了哪些附件类型?

    TEXT = ("text/plain", "txt")
    CSV = ("text/csv", "csv")
    TSV = ("text/tab-separated-values", "tsv")
    URI_LIST = ("text/uri-list", "uri")

    HTML = ("text/html", "html")
    XML = ("application/xml", "xml")
    JSON = ("application/json", "json")
    YAML = ("application/yaml", "yaml")
    PCAP = ("application/vnd.tcpdump.pcap", "pcap")

    PNG = ("image/png", "png")
    JPG = ("image/jpg", "jpg")
    SVG = ("image/svg-xml", "svg")
    GIF = ("image/gif", "gif")
    BMP = ("image/bmp", "bmp")
    TIFF = ("image/tiff", "tiff")

    MP4 = ("video/mp4", "mp4")
    OGG = ("video/ogg", "ogg")
    WEBM = ("video/webm", "webm")

    PDF = ("application/pdf", "pdf")

测试案例:

报告展示

 

7、命令行参数

pytest运行用例的时候可以加上allure标记用例的参数,或直接写在pytest.ini 文件中。

--allure-severities=SEVERITIES_SET
                        Comma-separated list of severity names. Tests only
                        with these severities will be run. Possible values
                        are: blocker, critical, normal, minor, trivial.
--allure-epics=EPICS_SET
                        Comma-separated list of epic names. Run tests that
                        have at least one of the specified feature labels.
--allure-features=FEATURES_SET
                        Comma-separated list of feature names. Run tests that
                        have at least one of the specified feature labels.
--allure-stories=STORIES_SET
                        Comma-separated list of story names. Run tests that
                        have at least one of the specified story labels.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
                        Url pattern for link type. Allows short links in test,
                        like 'issue-1'. Text will be formatted to full url
                        with python str.format().

选择运行你要执行epic的用例

pytest --alluredir ./report/allure --allure-epics=epic对大Story的一个描述性标签

选择运行你要执行features的用例

pytest --alluredir ./report/allure --allure-features=模块2

选择运行你要执行stories的用例

pytest --alluredir ./report/allure --allure-stories="用户故事:1"

参考至:pytest文档32-allure描述用例详细讲解 - 上海-悠悠 - 博客园

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值