pytest学习和使用25-当看到allure的动态生成标题和描述的特性时,直言简直太灵活了(allure.dynamic使用)

简介: pytest学习和使用25-当看到allure的动态生成标题和描述的特性时,直言简直太灵活了(allure.dynamic使用)

1 之前关于标题和描述是怎么做的?

1.1 之前标题使用@allure.title装饰器

  • 举个例子看下,之前已经学习过了,不再赘述了:
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/28 
# 文件名称:test_allure_title.py
# 作用:@allure.title特性
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson

import allure

@allure.title("用户正常登陆")
def test_login01():
    pass

@allure.title("用户名错误")
def test_login02():
    pass
  • 查看报告:

在这里插入图片描述

1.2 之前描述使用@allure.description装饰器

  • 举例:
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/28 
# 文件名称:test_allure_description.py
# 作用:@allure.description特性
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson

import allure
import pytest

# 使用方法一
@allure.description("""
这个用例的主要所用是验证?
哦,对了,我也不知道干啥的!!!
""")
def test_case01():
    num = 100 * (1 + 9)
    assert num == 1000

# 使用方法二
def test_case02():
    """
    这是一个用例!
    这个用例什么也没做!
    这个用例只是简单做个验证而已~
    """
    pass

在这里插入图片描述

2 allure.dynamic的动态功能怎么做?

2.1 allure.dynamic源码

class Dynamic(object):

    @staticmethod
    def title(test_title):
        plugin_manager.hook.add_title(test_title=test_title)

    @staticmethod
    def description(test_description):
        plugin_manager.hook.add_description(test_description=test_description)

    @staticmethod
    def description_html(test_description_html):
        plugin_manager.hook.add_description_html(test_description_html=test_description_html)

    @staticmethod
    def label(label_type, *labels):
        plugin_manager.hook.add_label(label_type=label_type, labels=labels)

    @staticmethod
    def severity(severity_level):
        Dynamic.label(LabelType.SEVERITY, severity_level)

    @staticmethod
    def feature(*features):
        Dynamic.label(LabelType.FEATURE, *features)

    @staticmethod
    def story(*stories):
        Dynamic.label(LabelType.STORY, *stories)

    @staticmethod
    def tag(*tags):
        Dynamic.label(LabelType.TAG, *tags)

    @staticmethod
    def link(url, link_type=LinkType.LINK, name=None):
        plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)

    @staticmethod
    def issue(url, name=None):
        Dynamic.link(url, link_type=LinkType.ISSUE, name=name)

    @staticmethod
    def testcase(url, name=None):
        Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)

2.2 从allure.dynamic源码可得出能动态设置的类型

allure.dynamic.title
allure.dynamic.description
allure.dynamic.description_html
allure.dynamic.label
allure.dynamic.severity
allure.dynamic.feature
allure.dynamic.story
allure.dynamic.tag
allure.dynamic.link
allure.dynamic.issue
allure.dynamic.testcase

2.3 类型说明和举例

2.3.1 allure.dynamic.title

  • 动态标题:
@allure.title("使用装饰器标题")
def test_title():
    print("CASE-01")
    allure.dynamic.title("使用动态标题")

在这里插入图片描述

2.3.2 allure.dynamic.description

  • 动态描述:
@allure.description("使用装饰器进行描述")
def test_description():
    print("CASE-02")
    allure.dynamic.description("使用动态描述")

在这里插入图片描述

2.3.3 allure.dynamic.description_html

  • 动态描述传一段html代码:
html_d = """
<h1>Test @allure.description_html</h1>
<table style="width:100%">
  <tr>
    <th>姓名</th>
    <th>成绩</th>
  </tr>
  <tr align="center">
    <td>张三</td>
    <td>100</td>
</table>
"""
def test_description_html():
    print("CASE-03")
    allure.dynamic.description_html(html_d)

在这里插入图片描述

2.3.4 allure.dynamic.label

  • 动态用例的标签;
  • 举例:
def test_label():
    print("CASE-04")
    allure.dynamic.label("this_label")

2.3.5 allure.dynamic.severity

  • 动态用例的优先级;
  • 举例:
@allure.severity("trivial")
def test_severity():
    print("CASE-05")
    allure.dynamic.severity("blocker")

在这里插入图片描述

2.3.6 allure.dynamic.feature

  • 模块名称 功能点的描述,往下是 story;
  • 举例:
@allure.feature('feature000')
def test_feature():
    print("CASE-06")
    allure.dynamic.feature("feature111")

在这里插入图片描述

2.3.7 allure.dynamic.story

  • 用户故事,往下是title;
  • 举例:
@allure.story('story222')
def test_story():
    print("CASE-07")
    allure.dynamic.story("story333")

在这里插入图片描述

2.3.8 allure.dynamic.tag

  • 用例的标记;
  • 举例:
def test_tag():
    print("CASE-08")
    allure.dynamic.tag("this is tag")

在这里插入图片描述

2.3.9 allure.dynamic.link

  • 定义一个链接;
  • 举例:
@allure.link("https://blog.csdn.net/NoamaNelson")
def test_link():
    print("CASE-09")
    allure.dynamic.link("https://juejin.cn/user/3655236621185246")

在这里插入图片描述

2.3.10 allure.dynamic.issue

  • 缺陷,对应缺陷管理系统里面的链接;
  • 举例:
def test_issue():
    print("CASE-10")
    allure.dynamic.issue('https://bbs.csdn.net/forums/NoamaNelson', '全栈测试技术社区')

在这里插入图片描述

2.3.11 allure.dynamic.testcase

  • 测试用例的链接地址;
  • 举例:
def test_testcase():
    print("CASE-11")
    allure.dynamic.issue("https://bbs.csdn.net/forums/NoamaNelson?category=10003&typeId=1566629", "测试用例地址")

在这里插入图片描述

3 本文涉及到的源码

# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/29 
# 文件名称:test_allure_dynamic.py
# 作用:allure.dynamic特性使用
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson

import allure

@allure.title("使用装饰器标题")
def test_title():
    print("CASE-01")
    allure.dynamic.title("使用动态标题")

@allure.description("使用装饰器进行描述")
def test_description():
    print("CASE-02")
    allure.dynamic.description("使用动态描述")

html_d = """
<h1>Test @allure.description_html</h1>
<table style="width:100%">
  <tr>
    <th>姓名</th>
    <th>成绩</th>
  </tr>
  <tr align="center">
    <td>张三</td>
    <td>100</td>
</table>
"""
def test_description_html():
    print("CASE-03")
    allure.dynamic.description_html(html_d)

def test_label():
    print("CASE-04")
    allure.dynamic.label("this_label")

@allure.severity("trivial")
def test_severity():
    print("CASE-05")
    allure.dynamic.severity("blocker")

@allure.feature('feature000')
def test_feature():
    print("CASE-06")
    allure.dynamic.feature("feature111")

@allure.story('story222')
def test_story():
    print("CASE-07")
    allure.dynamic.story("story333")

def test_tag():
    print("CASE-08")
    allure.dynamic.tag("this is tag")

@allure.link("https://blog.csdn.net/NoamaNelson")
def test_link():
    print("CASE-09")
    allure.dynamic.link("https://juejin.cn/user/3655236621185246")

def test_issue():
    print("CASE-10")
    allure.dynamic.issue('https://bbs.csdn.net/forums/NoamaNelson', '全栈测试技术社区')

def test_testcase():
    print("CASE-11")
    allure.dynamic.issue("https://bbs.csdn.net/forums/NoamaNelson?category=10003&typeId=1566629", "测试用例地址")
目录
相关文章
|
9月前
|
Web App开发 XML 前端开发
Selenium安装及八大元素定位方法&介绍及使用教程
Selenium是一个支持多种编程语言的自动化测试工具,用于Web应用的测试。它提供了多种元素定位策略,包括ID、Name、Class Name、Tag Name、Link Text、Partial Link Text、CSS Selector和XPath。安装Selenium需先确保Python和pip已安装,然后通过pip安装库,并下载对应浏览器的WebDriver。验证安装成功后,可通过编写简单脚本来打开网页并打印标题。注意WebDriver版本应与浏览器兼容,且可能需要额外的依赖包。文章还介绍了XPath的两种类型及其区别,推荐使用相对XPath以提高稳定性。
287 0
|
编解码 API 开发工具
FFmpeg入门及编译 1
FFmpeg入门及编译
208 1
|
4月前
|
前端开发 JavaScript UED
什么是防抖和节流?有什么区别?如何实现?
防抖和节流是前端优化技术,用于限制函数的执行频率。防抖是在一段时间内只执行一次函数,常用于搜索输入、窗口调整等场景;节流是在固定时间间隔内执行函数,适用于滚动事件、鼠标移动等。实现方式通常使用定时器。
|
9月前
|
Linux
Linux编译FFmpeg
Linux编译FFmpeg
180 0
|
8月前
|
存储 编解码 自然语言处理
一篇文章讲明白FFmpeg从入门到精通:SEI那些事
一篇文章讲明白FFmpeg从入门到精通:SEI那些事
185 0
|
9月前
|
编解码 自然语言处理 数据挖掘
Nomic Embed:能够复现的SOTA开源嵌入模型
Nomic-embed-text是2月份刚发布的,并且是一个完全开源的英文文本嵌入模型,上下文长度为8192。它在处理短文和长文本任务方面都超越了现有的模型,如OpenAI的Ada-002和text-embedding-3-small。该模型有137M个参数在现在可以算是非常小的模型了。
566 1
|
监控 安全 网络安全
【Docker Swarm】搭建Docker Swarm高可用集群(详细版)(上)
【Docker Swarm】搭建Docker Swarm高可用集群(详细版)
2562 0
【Docker Swarm】搭建Docker Swarm高可用集群(详细版)(上)
|
测试技术
Pytest 系列(29)- 详解 allure.dynamic 动态生成功能
Pytest 系列(29)- 详解 allure.dynamic 动态生成功能
537 0
Pytest 系列(29)- 详解 allure.dynamic 动态生成功能
|
存储 Java 程序员
【Go 进阶】Go 语言到底是值传递,还是引用传递?(一)
【Go 进阶】Go 语言到底是值传递,还是引用传递?(一)
|
SQL 机器人 测试技术
pytest+yaml框架环境配置和使用教程
pytest+yaml框架环境配置和使用教程

热门文章

最新文章