Pytest——》pytest+allure报告美化
2026/6/12 1:21:06 网站建设 项目流程

1、通过装饰器实现

#通过装饰器进行美化 import allure @allure.epic("PC端") #一级归类 @allure.feature("首页") #二级归类 class TestLogin(object): @allure.story("登录") #三级归类 @allure.title("用正确的账号密码登录") #用例标题 @allure.severity(allure.severity_level.CRITICAL) #优先级 # BLOCKER = 'blocker' 优先级等级 # CRITICAL = 'critical' # NORMAL = 'normal' # MINOR = 'minor' # TRIVIAL = 'trivial' # @classmethod def testlogin3(self): print('用类方法写用例') @allure.story("登录") @allure.title("用错误的账号密码登录") # @staticmethod def testlogin4(self): print('用实例方法写用例') @allure.story("登录") @allure.title("用不存在的账号密码登录") def testlogin5(self): print('用实例方法写用例')

报告呈现:

优先级呈现:

2、获取详细的响应日志:

import allure r3 = requests.post('http://localhost:8080/login', data={"username": "zhangsan", "password": "123456" }) allure.attach(str(r3.request.url), "请求地址", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.request.method), "请求方法", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.request.headers), "请求header", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.request.body), "请求body", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.status_code), "响应状态码", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.headers), "响应header", attachment_type=allure.attachment_type.TEXT) allure.attach(str(r3.text), "响应body", attachment_type=allure.attachment_type.TEXT)

报告示例:

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询