<9>pytest+allure:allure装饰器

发布时间:2022-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了<9>pytest+allure:allure装饰器脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

功能、步骤命名

功能名称:@allure.feature("功能名称") 子功能名称:@allure.story("子功能名称") 步骤细节:@allure.step("步骤细节")

按名称选择用例 根据功能名称选择:pytest 文件名 --allure-features "功能名称" 根据子功能名称选择:pytest 文件名 --allure-stories "子功能名称"

在生成的报告中,Behaviors项,可查看各功能、步骤信息

import allure


@allure.feature("登录模块")
class TestLogin:
    @allure.story("登录成功")
    def test_login_success(self):
        print("case:登录成功")

    @allure.story("登录失败1")
    def test_login_fail_a(self):
        print("case:登录失败,用户名缺失")

    @allure.story("登录失败2")
    def test_login_fail_b(self):
        print("case:登录失败,密码错误")

    @allure.story("登录步骤")
    def test_login_step(self):
        with allure.step("步骤1:打开应用"):
            pass
        with allure.step("步骤2:登录"):
            pass
        print("登录成功")

<9>pytest+allure:allure装饰器

用例命名

装饰器:@allure.title("用例名称")

import allure


@allure.feature("登录模块")
class TestLogin:
    @allure.story("登录成功")
    def test_login_success(self):
        print("case:登录成功")
    
    @allure.title("添加用例名称")
    def test_login_title(self):
        assert True

<9>pytest+allure:allure装饰器

设置用例级别 装饰器:@allure.severity(allure. severity_level.用例级别) 用例级别取值(大写) Blocker:中断 Critical :临界 Normal :普通 minor :次要 Trivial :轻微

按用例级别过滤用例:pytest 文件名 --allure-severities 用例级别(小写)

import allure


@allure.feature("登录模块")
class TestLogin:
    @allure.story("登录成功")
    def test_login_success(self):
        print("case:登录成功")

    @allure.story("用例级别")
    @allure.severity(allure.severity_level.NORMAL)
    def test_login_level(self):
        assert True

<9>pytest+allure:allure装饰器

附带链接

装饰器:@allure.testcase(url,urltitle)

import allure


@allure.feature("登录模块")
class TestLogin:
    @allure.story("链接")
    @allure.testcase("https://www.baidu.com/", "百度")
    def test_login_link(self):
        assert True

<9>pytest+allure:allure装饰器

添加文件

添加文本装饰器 @allure.attach("文本", "命名", attachment_type=allure.attachment_type.文本类型) 添加文件装饰器 @allure.attach.file("文件路径", name="命名", attachment_type=allure.attachment_type.文件类型)

import allure


@allure.feature("登录模块")
class TestAllure:
    @allure.story("attcah")
    def test_login_attach(self):
        # 添加文本
        allure.attach("文本", attachment_type=allure.attachment_type.TEXT)
        # 添加网页
        allure.attach("<body>网页</body>", "网页名称", attachment_type=allure.attachment_type.HTML)
        # 添加图片
        allure.attach.file("./resource/photo/photo.jpg", name="图片", attachment_type=allure.attachment_type.JPG)
        # 添加mp4
        allure.attach.file("./resource/video/video.mp4", name="视频", attachment_type=allure.attachment_type.MP4)
        assert True

<9>pytest+allure:allure装饰器

<9>pytest+allure:allure装饰器

<9>pytest+allure:allure装饰器

打开web服务,共享测试报告

  1. 生成html测试报告:allure generate log路径 -o 报告路径
  2. 启动web服务:allure open -h 本地IP -p 端口 报告路径

脚本宝典总结

以上是脚本宝典为你收集整理的<9>pytest+allure:allure装饰器全部内容,希望文章能够帮你解决<9>pytest+allure:allure装饰器所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: