Modern Python unittest HTML report generator.
Project description
UhtmlLit
现代化的 Python unittest HTML 测试报告生成器,支持全屏报告 UI、统计图表、截图附件、详情展开、主题切换、页面截图和 PDF 打印。
安装
pip install uhtml-lit
本地开发安装:
pip install -e .
基础用法
import unittest
from htmltestrunner import UhtmlLit
suite = unittest.TestLoader().loadTestsFromTestCase(YourTestCase)
with open("report.html", "wb") as f:
runner = UhtmlLit(
stream=f,
title="自动化测试报告",
description="项目接口自动化测试",
tester="QA Team",
open_in_browser=True,
)
runner.run(suite)
截图用法
import unittest
from selenium import webdriver
from htmltestrunner import UhtmlLit, 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(self.driver, "页面截图")
def tearDown(self):
self.driver.quit()
suite = unittest.TestLoader().loadTestsFromTestCase(TestDemo)
with open("report.html", "wb") as f:
UhtmlLit(stream=f, title="Selenium 测试报告").run(suite)
截图需要在 UhtmlLit.run(suite) 执行的测试上下文中调用。IDE 自带的 unittest runner 不会创建报告上下文,因此无法挂载截图。
API
UhtmlLit
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
stream |
file | sys.stdout |
HTML 报告输出流 |
title |
str | "Unit Test Report" |
报告标题 |
description |
str | "" |
报告描述 |
tester |
str | "QA Team" |
测试人员 |
verbosity |
int | 1 |
输出详细程度 |
open_in_browser |
bool | False |
生成后自动打开浏览器 |
attach_screenshot
支持传入:
- Selenium WebDriver 对象
- 图片文件路径
- 图片 bytes
- PIL Image 对象
示例
python examples/demo_basic.py
python examples/demo_selenium.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
uhtml_lit-1.0.6.tar.gz
(27.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
uhtml_lit-1.0.6-py3-none-any.whl
(26.4 kB
view details)
File details
Details for the file uhtml_lit-1.0.6.tar.gz.
File metadata
- Download URL: uhtml_lit-1.0.6.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0453ba5c5c7ada0db8ab2c565cb684bbc72419f32cda053398e66579efc5453d
|
|
| MD5 |
d07edf63de0d5a9dfda6f8afd0a5d803
|
|
| BLAKE2b-256 |
4e1d8ae1e313666b2f11b4c67349b1949216c8ed98316b14a7e25d937915686f
|
File details
Details for the file uhtml_lit-1.0.6-py3-none-any.whl.
File metadata
- Download URL: uhtml_lit-1.0.6-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce8a92dfc910f1df006470246f78da1cb3cb52c01e4301fcbdb12c6013796263
|
|
| MD5 |
b0b56e5f14b58761914509eb1ea314df
|
|
| BLAKE2b-256 |
d6864b0df77048d218af0a5d4897871f9d03fd9734bebb42e39a1947709d3db4
|