生成pytest-allure报告空白的问题---解决!

1、下载并安装allure

  • 下载allure,解压到指定文件夹。https://github.com/allure-framework/allure2/releases
  • 配置系统路径。右击【此电脑】>【属性】>【高级系统设置】>【环境变量】>【系统变量】,双击Path,添加系统变量:allure的bin路径。

  • 查看是否安装成功。cmd输入allure --version。显示版本号即成功。重启pycharm。

 2、pytest框架中使用allure步骤

  • 在pytest.ini文件中配置
[pytest]
#配置allure报告,-clean-alluredir 清除allure_results文件夹中上次的报告,无该命令会进行累加生成
addopts = -vs --alluredir=./allure_results --clean-alluredir
#测试用例的路径
testpaths =./test_cases
#模块名的规则
python_files = test_*.py
#类名的规则
python_classes = Test*
#方法名的规则
python_functions = test
  • 在run.py文件中使用
import time
import pytest
import os

if __name__ == '__main__':
    # 打开实时输出,Captrue Log只捕获sys.out,sys.err
    pytest.main(['--capture=sys'])
    time.sleep(3)
    # 使用allure generate -o 命令将./allure_results目录下的临时报告生成到reports目录下变成html报告
    os.system("allure generate ./allure_results -o ./reports --clean")
  • 运行run.py,生成报告

 

 

posted @ 2024-07-10 15:47  Zoe_Luck  阅读(1)  评论(0编辑  收藏  举报