【Python】高大上的测试报告-初识allure
一、allure下载及配置
1.allure下载网址:https://github.com/allure-framework/allure2/releases
2.下载zip后缀的文件,解压后可放任意位置
3.将bin路径配置到环境变量中
二、allure使用
1.安装:pip install allure-pytest
2.代码如下:
import os import allure import pytest test_datas_json_tuple = ({"username": "taomj", "password": "123456"}, {"username": "dxb", "password": "123456"}) @pytest.mark.parametrize('test_datas_json_tuple', test_datas_json_tuple) def test_parametrize_1(test_datas_json_tuple): print(f"\n字典为:{test_datas_json_tuple}") # 测试报告中添加 纯文本 allure.attach('纯文本', name='纯文本', attachment_type=allure.attachment_type.TEXT) # 测试报告中添加 html页面 allure.attach('<body>这是一段html块</body>', name='html页面', attachment_type=allure.attachment_type.HTML) # 测试报告中添加 图片 allure.attach('11.png', name='a.jpg', attachment_type=allure.attachment_type.PNG) if __name__ == '__main__': # 执行测试,并生成allure的json测试报告 pytest.main(["-vs", "demo_allure.py", f'--alluredir=allure_reports\\allure-report-json']) # 将json测试报告转换生成allure的html测试报告 os.system(f"allure generate allure_reports\\{time_stamp}_allure-report-json -o allure_reports\\allure-report-html -c") # 自动在浏览器中打开allure的html测试报告 os.system(f"allure open allure_reports\\allure-report-html")

浙公网安备 33010602011771号