HTMLTestRunner Lit 🎨
现代化的 Python unittest HTML 测试报告生成器
📸 预览
✨ 特性
- 🎨 Bootstrap 5 + ECharts 5 现代 UI 设计
- 🌓 深色/浅色主题 一键切换
- 📸 截图支持 自动捕获 Selenium 截图,支持轮播/网格预览
- 📱 响应式设计 完美支持移动端
- 📊 环形图表 可视化展示通过率
- 📋 测试详情 支持复制、展开/折叠
- 🧪 subTest 支持 完整支持子测试用例
- 🎯 自定义配色 支持自定义主题颜色
- 🚀 自动打开 测试完成后自动打开报告
🚀 安装
方式 1:从 PyPI 安装(推荐)
pip install htmltestrunner-lit
方式 2:从 GitHub 安装
pip install git+https://github.com/Aquarius-0455/HTMLTestRunner-Lit.git
方式 3:克隆后本地安装
git clone https://github.com/Aquarius-0455/HTMLTestRunner-Lit.git
cd HTMLTestRunner-Lit
pip install -e .
📖 使用方法
基础用法
import unittest
from htmltestrunner import HTMLTestRunnerLit
# 创建测试套件
suite = unittest.TestLoader().loadTestsFromTestCase(YourTestCase)
# 生成报告
with open('report.html', 'wb') as f:
runner = HTMLTestRunnerLit(
stream=f,
title='API 测试报告',
description='项目接口自动化测试',
tester='QA Team'
)
runner.run(suite)
自定义配置
runner = HTMLTestRunnerLit(
stream=f,
title='测试报告',
description='项目描述',
tester='测试人员',
verbosity=2,
open_in_browser=True # 测试完成后自动打开报告
)
📸 截图功能
在测试用例中导入并调用 attach_screenshot 即可将截图添加到报告中。
import unittest
from selenium import webdriver
from htmltestrunner import attach_screenshot
class TestDemo(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_example(self):
self.driver.get("https://www.baidu.com")
# 关键步骤:调用 attach_screenshot 并传入 driver 对象
attach_screenshot(self.driver, "页面截图描述")
def tearDown(self):
self.driver.quit()
🎨 主题配置
支持深色和浅色两种主题,用户可以在报告中手动切换。
📊 报告内容
- 测试概览: 总数、通过、失败、错误、跳过统计
- 可视化图表: 通过率环形图
- 详细结果: 每个测试用例的执行详情
- 错误追踪: 完整的错误堆栈信息
- 执行时间: 每个用例的执行耗时
🔧 API 参考
HTMLTestRunnerLit
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| stream | file | - | 输出文件流 |
| title | str | "Unit Test Report" | 报告标题 |
| description | str | "" | 报告描述 |
| tester | str | "QA Team" | 测试人员 |
| verbosity | int | 1 | 详细程度 |
| open_in_browser | bool | False | 测试完成后自动打开报告 |
📝 更新日志
v1.0.6
- 🔄 将
HTMLTestRunner重命名为HTMLTestRunnerLit,解决命名冲突问题
v1.0.5
- 📸 新增截图轮播与网格视图,支持多图自动切换
- 🔍 优化大图预览体验,支持键盘/点击左右切换
- 🎨 全新 Bootstrap 5 + ECharts 5 UI
- 🌓 深色/浅色主题切换
- 📱 响应式设计,完美支持移动端
- 📊 环形图表可视化展示通过率
- 🧪 完整支持 subTest 子测试用例
- 📋 测试详情支持复制、展开/折叠
- 🚀 支持
open_in_browser自动打开报告 - 👤 支持自定义
tester测试人员
📄 许可证
本项目采用 MIT 许可证。
🤝 贡献
欢迎提交 Issue 和 Pull Request!
⭐ Star History
如果这个项目对你有帮助,请给一个 Star ⭐
Metadata
Release files for htmltestrunner-lit 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| htmltestrunner_lit-1.0.6.tar.gz | 23.1 kB | Without provenance | Details for htmltestrunner_lit-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| htmltestrunner_lit-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for htmltestrunner_lit-1.0.6-py3-none-any.whl |
Total release size: 44.9 kB
Release files / htmltestrunner_lit-1.0.6.tar.gz
| Download URL | htmltestrunner_lit-1.0.6.tar.gz |
|---|---|
| Size | 23.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1068bcbb2c328a8eed4fa29fcb9832c09f8215cf2c94322aae96864eca2b4c1
|
|
BLAKE2b-256 checksum How to use checksums |
9c9d458b388508a60bb3f518dd73d0f746a64929114c5861237749b5432aed14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.6
|
Release files / htmltestrunner_lit-1.0.6-py3-none-any.whl
| Download URL | htmltestrunner_lit-1.0.6-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae5c5ad8031518278f24dd949c0c3bf6bcdac8d9d04d325416175e7c2e5f175c
|
|
BLAKE2b-256 checksum How to use checksums |
da04ca8810faafce6e681fbc5c3deb850f5364c6892e91095eacdb93ab73063c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.6
|
Security for htmltestrunner-lit 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.