如何将 pytest-html-reporter 生成的报告存储到自定义位置

问题描述

我正在使用 pytest-html-reporter 0.2.4 插件生成执行报告。 当我直接传递命令行参数“--html-report=./report/report.html”时,我能够在给定位置获取报告。

我想将报告存储在一个单独的位置,以执行日期(YYYYMMDD)作为文件名称,在 report_HHMM.html 中作为报告名称

这是我目前使用的逻辑

@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
    time_var = datetime.datetime.Now()
    # create report target dir
    reports_dir = Path('reports',time_var.strftime('%Y%m%d'))
    reports_dir.mkdir(parents=True,exist_ok=True)
    # line to be add for addopts
    args = f"--html-report=./{reports_dir}/report_{time_var.strftime('%H%M')}.html"
    config.addinivalue_line("addopts",args)
    print("inside config function",config.getini("addopts"))

这是我的 pytest.ini 文件

[pytest]
python_files = test_*
python_functions = test_*
python_classes = *Tests
addopts =

使用 config.getini("addopts") 我可以看到报告路径被添加到 addopts,但没有报告被添加到创建的目录

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)