【发布时间】:2019-06-05 12:20:36
【问题描述】:
我正在使用 pytest-html 插件。 在命令行中传递参数时会生成 html 报告。 需要自动创建html报告,并且在终端显示html报告链接。
【问题讨论】:
标签: report pytest pytest-html
我正在使用 pytest-html 插件。 在命令行中传递参数时会生成 html 报告。 需要自动创建html报告,并且在终端显示html报告链接。
【问题讨论】:
标签: report pytest pytest-html
您可以将cmdline参数放在根目录下的pytest.ini文件中
$ cat pytest.ini
[pytest]
addopts = --html=report.html --self-contained-html
【讨论】:
您可以通过在文件conftest.py 中编写pytest_cmdline_preparse() 挂钩来完成此操作
def pytest_cmdline_preparse(config, args):
html_file = func_to_generate_html_filename()
print('HTML report file:', html_file)
args.extend(['--html', html_file, '--self-contained-html'])
【讨论】:
另一种选择,就像 Nizar 的回答一样
def pytest_cmdline_preparse(config, args):
config.option.htmlpath = "my-report.html"
config.option.self_contained_html = True
【讨论】: