path+r'c+test.html',Python unittest如何生成HTMLTestRunner模块.pdf

Python unittest如如何何生生成成HTMLTestRunner模模块块

这篇文章主要介绍了Python unittest如何生成HTMLTestRunner模块,文中通过示例代码介绍的非常详细,对大家的

学习或者工作具有一 的参考学习价值,需要的朋友可以参考下

生成 HTMLTestRunner 模块

unittest 里面是不能生成 html 格式报告的,需要导入一个第三方的模块 :HTMLTestRunner

方法1.这个模块下载不能通过 pip 安装了,只能下载后手动导入,下载地址 :

/software/HTMLTestRunner.html

方法2.在 python 安装文件的 Lib 目录下新增文件 HTMLTestRunner.py

两种模板如下,建议使用第一种 (第一种模板更加美观)

文件内容如下 :

(1)第一种模板

# -*- coding: utf-8 -*-

"""

A TestRunner for use with the Python unit testing framework. It

generates a TML report to show the result at a glance.

The simplest way to use this is to invoke its main method. E.g.

import unittest

import TMLTestRunner

... define your tests ...

if __name__ == '__main__ ':

TMLTestRunner.main()

For more customization options, instantiates a TMLTestRunner object.

TMLTestRunner is a counterpart to unittest 's TextTestRunner. E.g.

# output to a file

fp = file('my_report.html', 'wb')

runner = TMLTestRunner. TMLTestRunner(

stream=fp,

title='My unit test ',

description='This demonstrates the report output by TMLTestRunner.'

)

# Use an external stylesheet.

# See the Template_mixin class for more customizable options

runner.STYLES EET_TMPL = ''

# run the test

runner.run(my_test_suite)

Copyright (c) 2004-2007, Wai Yip Tung

All rights reserved.

Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions are

met:

* Redistributions of source code must retain the above copyright notice,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值