pytest + yaml 框架 -49.allure报告自定义内容

发布时间 2023-07-10 19:53:52作者: 上海-悠悠

前言

v1.4.0 版本支持allure报告自定义内容

用例添加 allure 描述

用例中可以通过dynamic 添加以下内容

  • allure.dynamic.feature
  • allure.dynamic.link
  • allure.dynamic.issue
  • allure.dynamic.testcase
  • allure.dynamic.story
  • allure.dynamic.title
  • allure.dynamic.description

在test_a.yml 用例中示例

config:
  name: 用例描述


test_a1:
  name: 用例a1
  allure:
    feature: demo模块
    story: 用例场景
    title: 用例详细描述a1
    severity: critical

test_a2:
  name: 用例a2
  allure:
    feature: demo模块
    story: 用例场景
    title: 用例详细描述a2
    severity: critical

命令行执行用例,并启动allure服务查看报告

> pytest test_a.yml --alluredir ./report
> allure serve ./report

用例有多个步骤,添加step描述

在test_b.yml 用例中有多个步骤:

  • allure 描述可以放到第一个步骤
  • 其它步骤中的name对应的值,就是每个步骤的名称
  • 如果allure 中没有定义feature值,那么默认读取yaml 文件的名称

test_b.yml 示例

config:
  name: 用例描述


test_b2:
-
  allure:
    title: 用例有多个步骤情况
-
  name: 步骤1
  print: hello
-
  name: 步骤2
  print: world

config 中定义公共allure

同一个 yaml 文件中,有多个用例都需加相同的 allure 内容,可以在 config 中定义公共的allure内容
test_c.yml 内容

config:
  name: 用例描述
  allure:
    feature: config是公共的

test_c1:
  name: ss1
  print: hello world

test_c2:
  name: ss1
  allure:
    title: xxxxxxxxx
  print: hello world

test_c3:
  name: ss1
  allure:
    title: yyyyyyyy
  print: hello world