python-3.x - 如何将 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,但是没有报告被添加到创建的目录
解决方案
推荐阅读
- angularjs - ng-click 更改 var 的值
- c# - 如何将模型数据获取到视图下拉列表
- javascript - Javascript自定义按字符串属性排序
- python - 使用 Airflow 的 TriggerDagRunOperator 时,目标 DAG 运行被标记为“成功”,而没有完成子任务
- javascript - 为什么 node.js 中的异步函数不是异步的?
- opencv - 如何在考虑相机校准的情况下执行 2d 到 3d 重建
- javascript - 如何将点击事件传递或冒泡到另一层?
- database - 选择 Cosmos 分区键
- mysql - 是否可以禁止 MySQL 行修改?
- python - 递归导入语句