allure

category
自动化
date
May 25, 2026
icon
password
slug
allure
status
Published
summary
allure使用教程
tags
工作学习
type
Post
这里只介绍allure装饰器在pytest中的使用场景,装饰器只能在函数头部使用,简单说就是装饰器的上下文应该是def或是另一个装饰器

一、基础描述类

@allure.epic(”xxx”)
定义大模块(史诗级)
@allure.epic("用户中心系统")
@allure.feature(”xxx”)
定义功能模块
@allure.feature("登录模块")
@allure.story(”xxx”)
定义子功能/测试场景
@allure.story("账号密码登录")
@allure.title(”xxx”)
自定义用例标题(支持参数化)
@allure.title("登录测试”)
备注-参数化:

二、优先级与标签

@allure.severity()
定义用例优先级
@allure.severity(allure.severity_level.BLOCKER)
@allure.tag()
自定义标签
@allure.tag("冒烟测试", "核心功能")、@allure.tag("回归测试")
备注:
  • allure.severity_level.BLOCKER:阻塞(最高)
  • allure.severity_level.CRITICAL:严重
  • allure.severity_level.NORMAL:普通(默认)
  • allure.severity_level.MINOR:次要
  • allure.severity_level.TRIVIAL:轻微
筛选用例等级运行

三、步骤细化

@allure.step()
装饰器式
@allure.step("步骤1:输入账号密码(账号:{username})")
allure.step()
上下文管理器式
with allure.step("步骤4:输出日志"):(可写在代码内)

四、关联附件、链接

@allure.link()
关联普通链接
@allure.link("https://xxx.com/doc", name="接口文档")
@allure.issue()
关联缺陷/BUG链接
@allure.issue("https://bug.com/123", name="BUG-123")
@allure.testcase()
关联测试用例管理平台链接
@allure.testcase("https://testcase.com/456", name="测试用例TC-456")
allure.attach()
添加附件(文本/图片/JSON)
allure.attach.file("screenshot.png", name="失败截图", attachment_type=allure.attachment_type.PNG)
备注-针对allure.attach()
  • 传入的图片是代码中处理或者获取到的
  • 这个不是装饰器,是写到代码里的
上一篇
selenium
下一篇
自动化调研及总结
Loading...