python
install_error
ai_generated
true
FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'report.html'
FileNotFoundError: [Errno 2] No such file or directory: 'report.html'
ID: python/pytest-html-report-not-generated
80%修复率
86%置信度
0证据数
2024-08-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.x | active | — | — | — |
根因分析
pytest-html 插件未生成报告文件,通常是因为插件未安装、输出路径不正确,或测试运行在报告生成前崩溃。
English
pytest-html plugin did not generate the report file, often because the plugin is not installed, the output path is incorrect, or the test run crashed before report generation.
解决方案
-
95% 成功率
pip install pytest-html pytest --html=report.html --self-contained-html
-
88% 成功率
import tempfile import os report_path = os.path.join(tempfile.gettempdir(), 'report.html') # Run pytest with: --html=report_path
无效尝试
常见但无效的做法:
-
95% 失败
This creates an empty file that does not contain test results. The report will be useless.
-
90% 失败
This avoids the error but does not generate the report, defeating the purpose of using pytest-html.