pytest-html-reporter 使用教程

pytest-html-reporter 使用教程

pytest-html-reporterGenerates a static html report based on pytest framework项目地址:https://gitcode.com/gh_mirrors/py/pytest-html-reporter

1. 项目的目录结构及介绍

pytest-html-reporter/
├── README.md
├── pytest_html_reporter/
│   ├── __init__.py
│   ├── plugin.py
│   └── templates/
│       └── index.html
├── setup.py
└── tests/
    └── test_sample.py
  • README.md: 项目说明文档。
  • pytest_html_reporter/: 核心代码目录。
    • init.py: 模块初始化文件。
    • plugin.py: 插件主文件,包含报告生成的逻辑。
    • templates/: HTML模板文件夹。
      • index.html: 报告的HTML模板。
  • setup.py: 项目安装文件。
  • tests/: 测试用例目录。
    • test_sample.py: 示例测试文件。

2. 项目的启动文件介绍

项目的启动文件是 plugin.py,它包含了报告生成的主要逻辑。该文件定义了 pytest 插件的钩子函数,用于在测试运行结束后生成 HTML 报告。

# plugin.py
import pytest
from .reporter import generate_report

def pytest_addoption(parser):
    parser.addoption("--html-report", action="store", default="report", help="Path to the HTML report")

def pytest_terminal_summary(terminalreporter, exitstatus, config):
    report_path = config.getoption("--html-report")
    generate_report(terminalreporter, report_path)

3. 项目的配置文件介绍

项目的配置文件是 setup.py,它用于定义项目的元数据和依赖项,以便通过 pip 安装。

# setup.py
from setuptools import setup, find_packages

setup(
    name='pytest-html-reporter',
    version='0.2.9',
    description='Generates a static html report based on pytest framework',
    author='Prashanth Sams',
    packages=find_packages(),
    install_requires=[
        'pytest>=3.5',
    ],
    entry_points={
        'pytest11': [
            'html-reporter = pytest_html_reporter.plugin',
        ],
    },
)

通过 setup.py 文件,可以安装项目及其依赖项:

pip install .

这样,你就可以在 pytest 测试中使用 --html-report 选项来生成 HTML 报告了。

pytest-html-reporterGenerates a static html report based on pytest framework项目地址:https://gitcode.com/gh_mirrors/py/pytest-html-reporter

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

平奇群Derek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值