# BeautifulReport
一个基于unittest.TestResult模块实现的测试用例模板, 可把测试中的结果通过BeautifulReport整合成一个可视化的报表.
### 如何使用它?
```shell
>>> pip install BeautifulReport
```
```python
import unittest
from BeautifulReport import BeautifulReport
if __name__ == '__main__':
test_suite = unittest.defaultTestLoader.discover('./tests', pattern='test*.py')
result = BeautifulReport(test_suite)
result.report(filename='测试报告', description='测试deafult报告', report_dir='report', theme='theme_default')
```
### Report API简介
* BeautifulReport.report
* report (
filename -> 测试报告名称, 如果不指定默认文件名为report.html
description -> 测试报告用例名称展示
report_dir='.' -> 报告文件写入路径
theme='theme_default' -> 报告主题样式 theme_default theme_cyan theme_candy theme_memories
)
* BeautifulReport.add_test_img
如果使用报告过程中需要把测试报告的截图放在报告中, 可以使用add_test_img方法
* add_test_img (
*pargs
)
可以在测试用例上挂载一个装饰器, 实例内容如下
* 默认存放的图片路径是img, 需要在当前测试项目的启动路径下, 创建一个img文件夹
* 传递给装饰器的图片,在运行测试前可以不存在, 运行测试之后生成即可.
* 当文件在报告中展示后, 想要看到原图, 可以点击报告中的缩略图查看完整的截图
```python
import unittest
from BeautifulReport import BeautifulReport
class UnittestCaseSecond(unittest.TestCase):
""" 测试代码生成与loader 测试数据"""
def test_equal(self):
"""
test 1==1
:return:
"""
import time
time.sleep(1)
self.assertTrue(1 == 1)
@BeautifulReport.add_test_img('测试报告.png')
def test_is_none(self):
"""
test None object
:return:
"""
save_some_img('测试报告.png')
self.assertIsNone(None)
```
* 运行sample之后生成如下报告
![image](http://mocobk.test.upcdn.net/image/img20190325125101.jpg)
* 主题样式
![image](http://mocobk.test.upcdn.net/image/img20190325124850.jpg)
感谢原作者 [TesterlifeRaymond](https://github.com/TesterlifeRaymond/BeautifulReport) 的代码贡献,本人在原基础上修复了部分bug并增加了主题样式的自定义
Raw data
{
"_id": null,
"home_page": "https://github.com/mocobk/BeautifulReport",
"name": "BeautifulReport",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "mocobk",
"author_email": "mocobk@163.com",
"download_url": "https://files.pythonhosted.org/packages/b3/2c/b944e50172b72ce94f2b495a761e66ee3c4d517cee226469727749224f13/BeautifulReport-0.1.3.tar.gz",
"platform": "",
"description": "# BeautifulReport\n\n\u4e00\u4e2a\u57fa\u4e8eunittest.TestResult\u6a21\u5757\u5b9e\u73b0\u7684\u6d4b\u8bd5\u7528\u4f8b\u6a21\u677f, \u53ef\u628a\u6d4b\u8bd5\u4e2d\u7684\u7ed3\u679c\u901a\u8fc7BeautifulReport\u6574\u5408\u6210\u4e00\u4e2a\u53ef\u89c6\u5316\u7684\u62a5\u8868.\n\n### \u5982\u4f55\u4f7f\u7528\u5b83?\n\n```shell\n>>> pip install BeautifulReport\n```\n\n\n```python\n\nimport unittest\nfrom BeautifulReport import BeautifulReport\n\nif __name__ == '__main__':\n test_suite = unittest.defaultTestLoader.discover('./tests', pattern='test*.py')\n result = BeautifulReport(test_suite)\n result.report(filename='\u6d4b\u8bd5\u62a5\u544a', description='\u6d4b\u8bd5deafult\u62a5\u544a', report_dir='report', theme='theme_default')\n\n```\n\n### Report API\u7b80\u4ecb\n\n* BeautifulReport.report\n * report ( \n filename -> \u6d4b\u8bd5\u62a5\u544a\u540d\u79f0, \u5982\u679c\u4e0d\u6307\u5b9a\u9ed8\u8ba4\u6587\u4ef6\u540d\u4e3areport.html \n description -> \u6d4b\u8bd5\u62a5\u544a\u7528\u4f8b\u540d\u79f0\u5c55\u793a \n report_dir='.' -> \u62a5\u544a\u6587\u4ef6\u5199\u5165\u8def\u5f84 \n theme='theme_default' -> \u62a5\u544a\u4e3b\u9898\u6837\u5f0f theme_default theme_cyan theme_candy theme_memories \n )\n\n* BeautifulReport.add_test_img\n\n\u5982\u679c\u4f7f\u7528\u62a5\u544a\u8fc7\u7a0b\u4e2d\u9700\u8981\u628a\u6d4b\u8bd5\u62a5\u544a\u7684\u622a\u56fe\u653e\u5728\u62a5\u544a\u4e2d, \u53ef\u4ee5\u4f7f\u7528add_test_img\u65b9\u6cd5\n\n* add_test_img (\n *pargs\n)\n\n\u53ef\u4ee5\u5728\u6d4b\u8bd5\u7528\u4f8b\u4e0a\u6302\u8f7d\u4e00\u4e2a\u88c5\u9970\u5668, \u5b9e\u4f8b\u5185\u5bb9\u5982\u4e0b\n\n \n* \u9ed8\u8ba4\u5b58\u653e\u7684\u56fe\u7247\u8def\u5f84\u662fimg, \u9700\u8981\u5728\u5f53\u524d\u6d4b\u8bd5\u9879\u76ee\u7684\u542f\u52a8\u8def\u5f84\u4e0b, \u521b\u5efa\u4e00\u4e2aimg\u6587\u4ef6\u5939\n* \u4f20\u9012\u7ed9\u88c5\u9970\u5668\u7684\u56fe\u7247,\u5728\u8fd0\u884c\u6d4b\u8bd5\u524d\u53ef\u4ee5\u4e0d\u5b58\u5728, \u8fd0\u884c\u6d4b\u8bd5\u4e4b\u540e\u751f\u6210\u5373\u53ef.\n* \u5f53\u6587\u4ef6\u5728\u62a5\u544a\u4e2d\u5c55\u793a\u540e, \u60f3\u8981\u770b\u5230\u539f\u56fe, \u53ef\u4ee5\u70b9\u51fb\u62a5\u544a\u4e2d\u7684\u7f29\u7565\u56fe\u67e5\u770b\u5b8c\u6574\u7684\u622a\u56fe\n\n```python\nimport unittest\nfrom BeautifulReport import BeautifulReport\n\n\nclass UnittestCaseSecond(unittest.TestCase):\n \"\"\" \u6d4b\u8bd5\u4ee3\u7801\u751f\u6210\u4e0eloader \u6d4b\u8bd5\u6570\u636e\"\"\"\n \n def test_equal(self):\n \"\"\"\n test 1==1\n :return:\n \"\"\"\n import time\n time.sleep(1)\n self.assertTrue(1 == 1)\n \n @BeautifulReport.add_test_img('\u6d4b\u8bd5\u62a5\u544a.png')\n def test_is_none(self):\n \"\"\"\n test None object\n :return:\n \"\"\"\n save_some_img('\u6d4b\u8bd5\u62a5\u544a.png')\n self.assertIsNone(None)\n```\n\n* \u8fd0\u884csample\u4e4b\u540e\u751f\u6210\u5982\u4e0b\u62a5\u544a\n\n![image](http://mocobk.test.upcdn.net/image/img20190325125101.jpg)\n\n* \u4e3b\u9898\u6837\u5f0f\n\n![image](http://mocobk.test.upcdn.net/image/img20190325124850.jpg)\n\n\u611f\u8c22\u539f\u4f5c\u8005 [TesterlifeRaymond](https://github.com/TesterlifeRaymond/BeautifulReport) \u7684\u4ee3\u7801\u8d21\u732e\uff0c\u672c\u4eba\u5728\u539f\u57fa\u7840\u4e0a\u4fee\u590d\u4e86\u90e8\u5206bug\u5e76\u589e\u52a0\u4e86\u4e3b\u9898\u6837\u5f0f\u7684\u81ea\u5b9a\u4e49",
"bugtrack_url": null,
"license": "",
"summary": "unittest\u81ea\u52a8\u5316\u6d4b\u8bd5\u7684\u53ef\u89c6\u5316\u62a5\u544a\u6a21\u677f",
"version": "0.1.3",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b32cb944e50172b72ce94f2b495a761e66ee3c4d517cee226469727749224f13",
"md5": "5bd6eace38de9006145f3e7c82b078a0",
"sha256": "2c6b064248580e73b65feea36e1d74d5f3c1a0187825ab04ec909e3c016f138b"
},
"downloads": -1,
"filename": "BeautifulReport-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "5bd6eace38de9006145f3e7c82b078a0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 31035,
"upload_time": "2020-08-14T06:55:58",
"upload_time_iso_8601": "2020-08-14T06:55:58.450896Z",
"url": "https://files.pythonhosted.org/packages/b3/2c/b944e50172b72ce94f2b495a761e66ee3c4d517cee226469727749224f13/BeautifulReport-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-08-14 06:55:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mocobk",
"github_project": "BeautifulReport",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "beautifulreport"
}