You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10运行Pytest遇PluginValidationError错误求助

解决Pytest运行时PluginValidationError:unknown hook 'pytest_html_results_table_header'

错误根源

pytest_html_results_table_header是pytest-html插件专属的钩子函数,但你当前安装的是pytest-html-reporter——这是两个功能类似但完全独立的测试报告插件,后者并不提供这个钩子,因此pytest无法识别,抛出验证错误。你之前添加的pytest_json_runtest_metadata钩子和当前问题无关,所以无法解决报错。

解决方案

方案1:切换为pytest-html插件

如果你需要使用pytest_html_results_table_header这类钩子来自定义报告,建议替换插件:

  1. 卸载现有插件:
pip uninstall pytest-html-reporter -y
  1. 安装pytest-html:
pip install pytest-html

完成后无需修改conftest.py中的钩子代码,直接运行pytest即可。

方案2:保留pytest-html-reporter,移除不兼容钩子

如果不想更换插件,需要删除conftest.py中所有pytest_html_*开头的钩子函数(比如pytest_html_results_table_header、pytest_html_results_table_row等)。若需自定义报告,参考pytest-html-reporter的官方文档使用其专属的配置或钩子(比如以pytest_html_reporter_开头的钩子)。

内容的提问来源于stack exchange,提问作者Ajeet Yadawa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 02:52:21