Skip to main content

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

Metadata

Release files for uhtml-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)

Source distribution for uhtml-lit 1.0.6
File Size Uploaded
uhtml_lit-1.0.6.tar.gz 27.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uhtml-lit 1.0.6
File Interpreter ABI Platform
uhtml_lit-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 54.0 kB

Release files / uhtml_lit-1.0.6.tar.gz

Download URL uhtml_lit-1.0.6.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0453ba5c5c7ada0db8ab2c565cb684bbc72419f32cda053398e66579efc5453d
BLAKE2b-256 checksum
How to use checksums
4e1d8ae1e313666b2f11b4c67349b1949216c8ed98316b14a7e25d937915686f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / uhtml_lit-1.0.6-py3-none-any.whl

Download URL uhtml_lit-1.0.6-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce8a92dfc910f1df006470246f78da1cb3cb52c01e4301fcbdb12c6013796263
BLAKE2b-256 checksum
How to use checksums
d6864b0df77048d218af0a5d4897871f9d03fd9734bebb42e39a1947709d3db4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page