@allure.step()
通过 @allure.step() 装饰器,可以对每个测试用例进行详细的步骤说明。
- 参数说明:
@allure.step()只有一个参数,也就是结果图中TestBody中所显示的内容。 - 使用场景
适用于方法嵌套 - 参数传递
支持位置参数和关键字参数 {0},{arg2},可看第四步那里,如果函数的参数没有匹配成功就会报错哦
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # -*- 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("第五步") def test_with_nested_steps(): passing_step() step_with_nested_steps() |
结果显示如下:

allure.attach(添加附件)
作用:allure报告还支持显示许多不同类型的附件,可以补充测试结果;自己想输出啥就输出啥,挺好的
语法一: allure.attach(body, name, attachment_type, extension)
参数列表
body:要显示的内容(附件)
name:附件名字
attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
extension:附件的扩展名(比较少用)
语法二:allure.attach.file(source, name, attachment_type, extension)
source:文件路径,相当于传一个文件
attachment_type提供的附件类型:
