'''
1. 在suite.addTest时,可以把需要的用例先写入一个列表list中,list当做addTest的参数;
2. 在unittest.main(verbosity=2)中,默认为1,设置为2,可以输出每个case的执行情况;
3. 所有用例的开始结尾,只运行一遍setup 和 teardown,那么用setUpClass 和 tearDownClass,注意装饰器;
4. 在不需要的case上写入@unittest.skip('"I don\'t want to run this case."'),就可以跳过它 5. skip装饰器一共有三个:
unittest.skip(reason)、
unittest.skipIf(condition, reason)、
unittest.skipUnless(condition, reason),
skip无条件跳过,
skipIf当condition为True时跳过,
skipUnless当condition为False时跳过。
6. 文件日期命名:now = time.strftime('%Y-%m-%M %H_%M_%S') ''' 注意:
1. 未加入HTMLTestRunner时,如下不可以被注销:

2. https 报warnning,直接把相关文件中的函数暴力注销:

open -a pycharm /Users/vivi/Library/Python/3.6/lib/python/site-packages/requests/packages/urllib3/connectionpool.py

注销844-851

3. HTMLTestRunner 只支持python2.7,需要修改一些地方,这个可以google,到处都有,很全面;

from unittest import TestCase
import requests
from play import LoggIn
import unittest
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import HTMLTestRunner
import sys,time class TestLoggIn(TestCase): @classmethod
def setUpClass(self):
self.url = LoggIn.logUrl
print('do something before') @classmethod
def tearDownClass(self):
print('over')
pass # def setUp(self):
# self.url = LoggIn.logUrl
#
# def tearDown(self):
# pass def test_account_empty(self):
data = {'abbr': 'US', 'clientType': 'ios', 'dBrand': 'apple', 'imagePHeight': '736', 'imagePixels': '828', 'osVersion': 'iOS10.3', 'password': '******', 'rememberMe': '1','st': '1496557229892', 'udid': '9fa81f8b42277b1e9567e'} r= requests.post(self.url,data=data,verify=False)
result = r.json()
self.assertEqual(result['code'],'220120')
self.assertEqual(result['message'],'is empty!')
self.assertEqual(result['result'],'account or password is null') # @unittest.skip('"I don\'t want to run this case."')
def test_account_error(self):
data = {'abbr': 'US', 'clientType': 'ios', 'dBrand': 'apple', 'imagePHeight': '736', 'imagePixels': '828', 'loginAccount':'name123','osVersion': 'iOS10.3', 'password': '******', 'rememberMe': '1','st': '1496557229892', 'udid': '9fac416e2d75e77b1e9567e'} r= requests.post(self.url,data=data,verify=False)
result = r.json()
self.assertEqual(result['code'],'22012811')
self.assertEqual(result['message'],'account or password error thrid!')
self.assertEqual(result['result'],'account or password error third!') def test_account_pass(self):
data = {'abbr': 'US', 'clientType': 'ios', 'dBrand': 'apple', 'imagePHeight': '736', 'imagePixels': '828', 'loginAccount':'name','osVersion': 'iOS10.3', 'password': '***', 'rememberMe': '1','st': '1496557229892', 'udid': '9fac416e2d75e42277b1e9567e'} r= requests.post(self.url,data=data,verify=False)
result = r.json()
self.assertEqual(result['code'],'200')
self.assertEqual(result['message'],'success!')
self.assertEqual(result['result']['loginAccount'],'name')
self.assertEqual(result['result']['memberPicture'],'pre/diyrelease/320187/150365518619893164.jpg') if __name__ == '__main__':
# verbosity=2 详细输出每个case的执行结果
# verbosity=1 只输出对错:失败是 F,出错是 E,跳过是 S
# verbosity=0 不输出任何结果 # unittest.main(verbosity=2)
suite = unittest.TestSuite() # 添加到TestSuite中的case是会按照添加的顺序执行的
suite.addTest(TestLoggIn('test_account_empty'))
suite.addTest(TestLoggIn('test_account_error'))
suite.addTest(TestLoggIn('test_account_pass')) # 这样 用列表,和上面一个个添加一样的效果
# tests = [TestLoggIn('test_account_empty'),TestLoggIn('test_account_error'),TestLoggIn('test_account_pass')]
# suite.addTest(tests) # 执行测试用例
# runner = unittest.TextTestRunner()
# runner.run(suite) # 执行并写入文件
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestLoggIn)) # now = time.strftime('%Y-%m-%M %H_%M_%S',time.localtime(time.time()))
now = time.strftime('%Y-%m-%M %H_%M_%S')
filename ='/Users/vivi/PycharmProjects/testreport_html/report/'+ now + '_result.html'
# filename = '/Users/vivi/PycharmProjects/a.html'
fp = open(filename,'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
title='Play LogIn Test',
description='generated by HTMLTestRunner.',
verbosity=2
)
runner.run(suite)
fp.close()

  

执行成功:

执行失败:

python3.6的requests库&HTMLTestRunner实现测试报告的更多相关文章

  1. python3爬虫之requests库基本使用

    官方文档链接(中文) https://2.python-requests.org/zh_CN/latest/ requests  基于  urllib3 ,python编写. 安装 pip insta ...

  2. python3+requests库框架设计01-自动化测试框架需要什么?

    什么是自动化测试框架 关于自动化测试框架的定义有很多,在我大致理解下就是把能实现不同功能的软件组合在一起,实现特定的目的,这就是一个简单的自动化测试框架. 接口自动化测试框架核心无非是选择 一个用来编 ...

  3. Python3.6安装及引入Requests库

    本博客可能没有那么规范,环境之类的配置.只是让你直接开始编程写python. 至于各种配置网络上有多种方法. 本文仅代表我的观点的一种方法. 电脑环境:win10 64位 第一步:下载python. ...

  4. Python3下requests库发送multipart/form-data类型请求

    [本文出自天外归云的博客园] 要模拟multipart/form-data类型请求,可以用python3的requests库完成.代码示例如下: #请求的接口url url = "url&q ...

  5. Python3.x(windows系统)安装requests库

    Python3.x(windows系统)安装requests库 cmd命令: pip install requests 执行结果:

  6. Python3 urllib库和requests库

    1. Python3 使用urllib库请求网络 1.1 基于urllib库的GET请求 请求百度首页www.baidu.com ,不添加请求头信息: import urllib.requests d ...

  7. python3好用的requests库

    python3好用的requests库 requests是什么? requests是基于urllib编写的http库,支持python3,比urllib更好用,更简单.之前使用python写一些htt ...

  8. 关于python3 使用pycharm+unittest+html+HTMLTestRunner 测试用例运行正常,但却不能生成测试报告的解决方法

    关于python3 使用pycharm+unittest+html+HTMLTestRunner 测试用例运行正常,但却不能生成测试报告的解决方法 这个问题我也遇到过,以下是解决办法   该方法适用于 ...

  9. python3添加requests库

    1.资源下载 https://codeload.github.com/psf/requests/zip/master https://www.python.org/ https://files.pyt ...

随机推荐

  1. bzoj 3732: Network【克鲁斯卡尔+树链剖分】

    先做最小生成树,这样就保证了最大值最小 然后随便用个什么东西维护一下最大值,我用的树剖log^2,倍增会更快 #include<iostream> #include<cstdio&g ...

  2. bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头【瞎搞】

    某种意义上真毒瘤?我没看懂题啊...于是看了题解 就是筛约数的那种方法,复杂度调和级数保证O(nlogn) 所以这题啥意思啊 #include<iostream> #include< ...

  3. 【底层原理】高级开发必须懂的"字节对齐"

    认识字节对齐之前,假定int(4Byte),char(1Byte),short(2Byte) 认识字节对齐 先看段代码: struct Data1 { char a; int b; short c; ...

  4. Hdu 5384 Danganronpa (AC自动机模板)

    题目链接: Hdu 5384 Danganronpa 题目描述: 给出n个目标串Ai,m个模式串Bj,问每个目标串中m个模式串出现的次数总和为多少? 解题思路: 与Hdu 2222  Keywords ...

  5. 51nod 1088 最长回文子串

    1088 最长回文子串 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串. 输入一 ...

  6. treap板子(洛谷 P3369 【模板】普通平衡树(Treap/SBT))

    由于有相同的数,每个节点加一个权值表示此数出现的次数 #include<cstdio> #include<cstdlib> #include<ctime> #inc ...

  7. 题解报告:hdu 2059 龟兔赛跑

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击—— ...

  8. 设置UITableViewCell 选中时的背景颜色

    自定义Cell如图 一个View上面放了四个Label 分别连线到.m文件中 @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @pro ...

  9. 基于Windows7下snort+apache+php 7 + acid(或者base) + adodb + jpgraph的入侵检测系统的搭建(图文详解)(博主推荐)

    为什么,要写这篇论文? 是因为,目前科研的我,正值研三,致力于网络安全.大数据.机器学习.人工智能.区域链研究领域! 论文方向的需要,同时不局限于真实物理环境机器实验室的攻防环境.也不局限于真实物理机 ...

  10. [转]asp.net 跨域单点登录

    本文转自:http://tech.e800.com.cn/articles/2009/814/1250212319986_1.html 单点登录(Single Sign On),简称为 SSO,是目前 ...