allure报告中添加附件
类型 | 类型值 |
---|---|
文本 | allure.attachment_type.TEXT |
CSV | allure.attachment_type.CSV |
图片 | allure.attachment_type.JPG或PNG |
allure.attachment_type.PDF | |
html文件 | allure.attachment_type.HTML |
json文件 | allure.attachment_type.JSON |
xml文件 | allure.attachment_type.XML |
mp4 | allure.attachment_type.MP4 |
语法示例
allure.attach(body,name,attachment_type,extention)
参数说明:
添加请求和响应日志附件
import requestsimport allureimport jsondef test_allure():
url = 'http://httpbin.org/post'
body = { "user": "test_xx", "password": "123456"
} allure.attach( json.dumps(body), 'request', allure.attachment_type.TEXT)
res = requests.post(url, json=body)
print(f"返回结果:{res.text}")
allure.attach( res.text, 'response', allure.attachment_type.TEXT)
allure报告中查看附件
语法:
allure.attach.file(source, name, attachment_type, extension)
参数解释:
添加图片示例
import requestsimport allureimport jsonfrom pathlib import Pathdef test_allure_img():
"""添加图片附件"""
print("----添加附件")
file_path = Path(__file__).parent.joinpath('abc.jpg')
allure.attach.file( file_path, '添加的图片', allure.attachment_type.JPG, extension="jpg")