
一、报告类别allure.epic最高级别的分类表示一个大的功能、模块或业务场景。功能模块allure.feature表示一个功能模块或业务子场景位于史诗下。主流程allure.story表示一个具体的测试场景位于特性下。具体主流程或分支流程-如增、删、改allure.title表示故事中的一个具体测试场景的标题。from allure_commons.types import AttachmentType是用于Allure 测试报告的附件类型定义模块它提供了一些预定义的附件类型帮助你将文件、文本、图片等信息附加到 Allure 测试报告中。二、报告标签搜索在报告输入框输入 tag: 相应标签 就可以搜索对应的标签可以在团队协作中可以打上名称通过pytest.mark.name打上名称标签让人一看就知道是谁的问题主要功能明确附件类型当你将文件、日志、截图或其他数据附加到 Allure 报告时可以通过指定附件类型让报告正确识别和渲染这些附件。比如AttachmentType.TEXT表示普通文本AttachmentType.PNG表示图片。增强报告的可读性不仅展示测试用例的运行结果还可以附加更多上下文信息例如请求的 JSON 数据、响应日志、截图等帮助调试和分析失败原因。二、AttachmentTypefromallure_commons.typesimportAttachmentType常用的附件类型以下是AttachmentType中的一些预定义类型及其作用附件类型描述AttachmentType.TEXT普通文本附件比如日志或控制台输出。AttachmentType.JSONJSON 格式的数据附件用于附加请求或响应数据。AttachmentType.HTMLHTML 格式附件比如网页内容或报告片段。AttachmentType.PNGPNG 格式的图片附件用于附加截图或图表。AttachmentType.JPGJPG 格式的图片附件。AttachmentType.CSVCSV 格式的附件用于附加表格或数据文件。AttachmentType.XMLXML 格式的数据附件。AttachmentType.MARKDOWNMarkdown 格式的文本附件用于附加格式化文本或文档。AttachmentType.PDFPDF 文件附件用于附加文档或截图。示例用法在测试中使用AttachmentType将信息附加到 Allure 报告1. 附加文本日志importallure allure.attach(这是测试日志内容,nameTest Log,attachment_typeAttachmentType.TEXT)2. 附加 JSON 数据response_data{status:200,message:Success}allure.attach(str(response_data),nameResponse JSON,attachment_typeAttachmentType.JSON)3. 附加截图withopen(screenshot.png,rb)asimage:allure.attach(image.read(),nameScreenshot,attachment_typeAttachmentType.PNG)4. 附加 HTMLhtml_contenthtmlbodyh1Hello, World!/h1/body/htmlallure.attach(html_content,nameSample HTML,attachment_typeAttachmentType.HTML)在接口测试中的典型用法结合 Schemathesis 和 Allure附加接口请求和响应的数据schema.parametrize()deftest_api(case):# 调用接口responsecase.call()# 附加请求信息allure.attach(fRequest URL:{case.path}\nMethod:{case.method}\nHeaders:{case.headers},nameRequest Info,attachment_typeAttachmentType.TEXT)# 附加响应信息allure.attach(response.text,nameResponse Body,attachment_typeAttachmentType.JSON)# 验证响应case.validate_response(response)总结AttachmentType是 Allure 提供的一种类型标识工具用于明确附件的格式和用途。通过它你可以将各种数据如日志、截图、请求/响应信息附加到测试报告中让测试结果更加直观和便于分析。