pytest(20):allure的特性,@allure.description()、@allure.title()的详细使用

前言

上一篇文章介绍了两种allure的特性

  • @allure.step() 装饰器:可以设置测试步骤,让测试用例的执行过程更加详细
  • allure.attach() 函数:可以设置需要显示在allure报告的附件,包含了多种类型,可以通过allure.attachment_type查看支持的类型

这一篇幅,我们主要来讲解另外两个特性,可以增加报告的可读性哦!

  • @allure.description()
  • @allure.title()

它们用法极其相近,只是作用不一样而已

@allure.description()

    • 作用:
      添加详细的测试用例描述
    • 使用方法
      (1)在测试用例前使用@allure.description()
      (2)在测试用例下使用""" “”"进行声明
      (3)使用@allure.description_html()添加描述
# -*- coding: utf-8 -*-
import yaml
import pytest
import allure


@allure.step("第一步")
def passing_step():
pass


@allure.step("第二步")
def step_with_nested_steps():
nested_step()


@allure.step("第三步")
def nested_step():
nested_step_with_arguments(1, 'abc')


@allure.step("第四步{0},{arg2}")
def nested_step_with_arguments(arg1, arg2):
pass


方法一:

@allure.step("第五步")
@allure.description("""
这是第五步的一个简单说明""")
def test_with_nested_steps():
# """
# 这是第五步的一个简单说明
# """
passing_step()
step_with_nested_steps()


方法二:

def test_descripyion():
"""
这是第五步的一个简单说明
"""


passing_step()
step_with_nested_steps()

方法三:

@allure.description_html("""
<h1>Test with some complicated html description</h1>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr align="center">
<td>William</td>
<td>Smith</td>
</table>
""")
def test_descripyion_html():
passing_step()
step_with_nested_steps()

结果显示:

@allure.title()

    • 作用
      对测试用例添加标题,使其更具有可读性
      支持占位符传递关键字参数哦(动态标题,结合 @pytest.mark.parametrize 使用)
    • 结合参数传递使用
@allure.step("第五步")
@allure.title("csdn测试")
def test_with_nested_steps():
# """
# 这是第五步的一个简单说明
# """
passing_step()
step_with_nested_steps()

结果显示: 

 

结合参数传递使用

@allure.title("多个参数{name},{phone},{age}")
@pytest.mark.parametrize("name,phone,age", [
(1, 2, 3),
(4, 5, 6),
(7, 8, 9)
])
def test_test_test(name, phone, age):
print(name, phone, age)

结果展示:

posted @ 2021-08-17 10:48  Tester-**  阅读(144)  评论(0编辑  收藏  举报