前言
- 在测试过程中,可能遇到各种各样的问题,需要在关键的地方,附加文本、图片以及html网页,用来补充测试步骤或测试结果,下面一起来学习如何在allure报告中增加这些信吧。
支持添加的类型
class AttachmentType(Enum): def __init__(self, mime_type, extension): self.mime_type = mime_type self.extension = extension TEXT = ("text/plain", "txt") CSV = ("text/csv", "csv") TSV = ("text/tab-separated-values", "tsv") URI_LIST = ("text/uri-list", "uri") HTML = ("text/html", "html") XML = ("application/xml", "xml") JSON = ("application/json", "json") YAML = ("application/yaml", "yaml") PCAP = ("application/vnd.tcpdump.pcap", "pcap") PNG = ("image/png", "png") JPG = ("image/jpg", "jpg") SVG = ("image/svg-xml", "svg") GIF = ("image/gif", "gif") BMP = ("image/bmp", "bmp") TIFF = ("image/tiff", "tiff") MP4 = ("video/mp4", "mp4") OGG = ("video/ogg", "ogg") WEBM = ("video/webm", "webm") PDF = ("application/pdf", "pdf")
使用实例
# -*- coding: utf-8 -*- # @Time : 2022/9/11 # @Author : 大海 import os import allure @allure.title('添加文本') def test_attach_text(): # 第一参数为添加的内容,name为展示的标题,attachment_type 是添加的类型 allure.attach("大家好,我是测试小白!", name="纯文本", attachment_type=allure.attachment_type.TEXT) @allure.title('添加HTML') def test_attach_html(): allure.attach("<body>大家好,我是测试小白! <a href='https://blog.csdn.net/IT_heima'>点击跳转博客</a></body>", name="html页面", attachment_type=allure.attachment_type.HTML) @allure.title('添加图片') def test_attach_pic(): allure.attach.file("..\study.jpg", name="图片", attachment_type=allure.attachment_type.PNG) @allure.title('添加PDF') def test_attach_pdf(): allure.attach.file("..\pytest.pdf", name="PDF", attachment_type=allure.attachment_type.PDF) if __name__ == '__main__': os.system('pytest -s test_68.py --alluredir=./allure-report --clear') # 打开allure报告 (目录与上面生成结果目录需一致) os.system('allure serve ./allure-report')
查看报告