python install_error ai_generated true

FileNotFoundError: [Errno 2] No such file or directory: 'report.html'

ID: python/pytest-html-report-not-generated

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-08-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.x active

Root Cause

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.

generic

中文

pytest-html 插件未生成报告文件,通常是因为插件未安装、输出路径不正确,或测试运行在报告生成前崩溃。

Workarounds

  1. 95% success
    pip install pytest-html
    pytest --html=report.html --self-contained-html
  2. 88% success
    import tempfile
    import os
    
    report_path = os.path.join(tempfile.gettempdir(), 'report.html')
    # Run pytest with: --html=report_path

Dead Ends

Common approaches that don't work:

  1. 95% fail

    This creates an empty file that does not contain test results. The report will be useless.

  2. 90% fail

    This avoids the error but does not generate the report, defeating the purpose of using pytest-html.