支持类型:
class AttachmentType(Enum):def __init__(self, mime_type, extension):self.mime_type = mime_typeself.extension = extensionTEXT = ("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")
使用方法
@allure.title("Test with CSV attachment")
def test_with_xlsx_attachment1():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/excel_example.csv'with open(file_path, 'rb') as f:allure.attach(f.read(), name="MyCSVAttachment", attachment_type=allure.attachment_type.CSV)# 测试逻辑assert True@allure.title("Test with TXT attachment")
def test_with_xlsx_attachment2():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/file1.txt'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My txt Attachment", attachment_type=allure.attachment_type.TEXT)# 测试逻辑assert True@allure.title("Test with LOG attachment")
def test_with_xlsx_attachment3():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/file2.log'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My txt Attachment", attachment_type=allure.attachment_type.TEXT)# 测试逻辑assert True@allure.title("Test with HTML attachment")
def test_with_xlsx_attachment4():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/BigDataplotly.html'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My txt Attachment", attachment_type=allure.attachment_type.HTML)# 测试逻辑assert True@allure.title("Test with JPG attachment")
def test_with_xlsx_attachment5():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/image.jpg'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My jpg Attachment", attachment_type=allure.attachment_type.JPG)# 测试逻辑assert True@allure.title("Test with PCAP attachment")
def test_with_xlsx_attachment6():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/10020_10021_5000_93_138651_3.pcap'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My jpg Attachment", attachment_type=allure.attachment_type.PCAP)# 测试逻辑assert True@allure.title("Test with YAML attachment")
def test_with_xlsx_attachment7():# Allure测试报告添加附件file_path = 'D:/code/AutoTest/TestDatas/ModelE/test_varArgs.yml'with open(file_path, 'rb') as f:allure.attach(f.read(), name="My yaml Attachment", attachment_type=allure.attachment_type.YAML)# 测试逻辑assert True
结果展示
下载