2024-06-07 15:11:31 发布
网友
我想用以下方式包装pytest html插件:
我可以通过实现pytest_addoption(parser)函数来添加选项,但在第二件事上遇到了麻烦
pytest_addoption(parser)
我能做的是:实现一个hook frmo pytest html。但是,我必须访问我的选项X,以便执行操作。问题是,pytest html的钩子没有将“request”对象作为参数提供,因此我无法访问选项值
我可以有一个钩子的附加参数吗?还是像这样
您可以将其他数据附加到报表对象,例如通过围绕pytest_runtest_makereport钩子的自定义包装器:
pytest_runtest_makereport
@pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() report.config = item.config
现在config对象可以通过所有报告挂钩中的report.config访问,包括pytest-html的挂钩:
config
report.config
pytest-html
def pytest_html_report_title(report): """ Called before adding the title to the report """ assert report.config is not None
您可以将其他数据附加到报表对象,例如通过围绕
pytest_runtest_makereport
钩子的自定义包装器:现在
config
对象可以通过所有报告挂钩中的report.config
访问,包括pytest-html
的挂钩:相关问题 更多 >
编程相关推荐