We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode pytest-html - a plugin that generates HTML reports for test results

pytest-html - a plugin that generates HTML reports for test results

2025/3/27
logo of podcast Test & Code

Test & Code

AI Deep Dive AI Chapters Transcript
People
B
Brian Okken
Topics
Brian Okken: pytest-html插件是我最喜欢的pytest插件之一,它能够生成简洁易懂的HTML测试报告,方便查看测试结果。该插件易于使用,只需在运行pytest时添加简单的命令行参数即可生成报告,并且可以自定义报告的输出格式,例如,可以选择将所有内容都包含在一个HTML文件中,或者将CSS等额外内容放在单独的目录中。 生成的报告包含环境信息,例如Python版本、操作系统和使用的插件等,以及测试运行的摘要,包括测试数量、耗时和各种结果类型(例如通过、失败、跳过等)的数量。报告中最重要的部分是结果表格,该表格以颜色区分不同的结果状态(例如通过为绿色,失败为红色),并显示测试名称和持续时间。表格中的列还可以排序,方便查找特定信息,例如查找耗时最长的测试。 点击结果表格中的结果可以展开显示详细的信息,例如回溯信息,这对于调试失败的测试非常有用。该报告可以用于本地调试,也可以链接到CI服务器中。 pytest-html插件的一个重要特性是其高度的可定制性。其文档清晰易懂,方便用户学习和使用。用户可以自定义CSS样式,并向环境部分添加额外的信息,例如代码版本、硬件配置等。pytest-metadata插件可以简化这个过程。用户还可以自定义结果表格,例如添加、自定义或隐藏列,甚至添加链接、额外数据和图片。 报告顶部的环境部分默认包含一些信息,例如Python版本、平台等,但用户可以使用pytest-metadata插件进行扩展,添加更多有用的信息,或者移除不需要的信息。用户还可以通过pytest_html_results_summary hook函数向摘要部分添加信息,例如将运行时收集的聚合测试数据添加到报告中。为了避免信息过多,可以将额外信息放在一个可折叠的details HTML块中,只显示一行摘要,用户点击后才能查看详细信息。

Deep Dive

Shownotes Transcript

pytest-html has got to be one of my all time favorite plugins. pytest-html is a plugin for pytest that generates a HTML report for test results. This episode digs into some of the super coolness of pytest-html.

**Sponsored by: **

  • The Complete pytest course) is now a bundle, with each part available separately.

  • pytest Primary Power) teaches the super powers of pytest that you need to learn to use pytest effectively.

  • Using pytest with Projects) has lots of "when you need it" sections like debugging failed tests, mocking, testing strategy, and CI

  • Then pytest Booster Rockets) can help with advanced parametrization and building plugins.

  • Whether you need to get started with pytest today, or want to power up your pytest skills, PythonTest) has a course for you.

** ★ Support this podcast on Patreon ★) **