unittest===unittest 的几种执行方式
#demo.py import requests
import json class RunMain:
def __init__(self, url, method, data=None):
self.data = data
self.url = url
self.method = method
self.res = self.run_main() def url_post(self):
res = requests.post(url = self.url, data = self.data).json()
return res def url_get(self):
res = requests.get(url= self.url, data = self.data).json()
return res # res 返回的json数据
# indent 缩进展示
# sort_keys 排序
# return json.dumps(res,indent = 2, sort_keys = True) #再封装一个方法,让它执行post和get请求 def run_main(self):
res = None
if self.method == 'GET':
res = self.url_get() else:
res = self.url_post()
return res if __name__ == "__main__":
url_p = "https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/upload"
data = {
"hello":"world",
"botoo":""
} url_g ="https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/query" g = RunMain(url_g,"GET").res print(g)
p = RunMain(url_p,"POST",data = data ).res print(p)
#unittest-test.py import unittest
from demo import RunMain
import HtmlTestRunner class TestMethod(unittest.TestCase):
#类方法 @classmethod
def setUpClass(cls):
print("类执行之前的方法") @classmethod
def tearDownClass(cls):
print("类执行之后的方法") #每次方法之前执行
def setUp(self):
print("setup") def test_01(self): url_p = "https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/upload"
data = {
"hello":"world",
"botoo":""
} res = RunMain(url_p,"POST",data).res
#print(res)
self.assertIn("undefined_http",str(res['data']))
globals()['img'] = res['data']['img'] #加入缓存 def test_02(self):
print(img) url_g ="https://easy-mock.com/mock/5d0cce9536b12b2b2e62adc7/example/query"
res = RunMain(url_g,"GET").res
self.assertEqual("hah",res['data']['name'])
#print(res) @unittest.skip
def test_03(self):
print(img) #每次方法之后执行
def tearDown(self):
print("teardown") if __name__ == "__main__":
"""
#方法一:
unittest.main()
""" """
#方法二:
#加入容器中执行
suite=unittest.TestSuite()
suite.addTest(TestMethod("test_01"))
suite.addTest(TestMethod("test_02"))
suite.addTest(TestMethod("test_03"))
unittest.TextTestRunner().run(suite)
""" """
#方法三:
#加入测试报告,执行所有case
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
""" """
#方法四:
#加入测试报告,执行加入容器的case
suite = unittest.TestSuite()
suite.addTest(TestMethod("test_01"))
suite.addTest(TestMethod("test_02"))
suite.addTest(TestMethod("test_03"))
testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir')
testRunner.run(suite)
"""
unittest===unittest 的几种执行方式的更多相关文章
- PyCharm上unittest 测试用例两种执行方式
每次讲到unittest测试框架的时候,经常有同学在群里反映,为啥我的运行不是按照我往suite里添加的用例顺序执行的,为什么别人的能跑出来报告,我的就不行... 当然,首先确认代码是OK的,如果代码 ...
- 读书笔记——spring cloud 中 HystrixCommand的四种执行方式简述
读了<Spring Cloud 微服务实战>第151-154页, 总结如下: Hystrix存在两种Command,一种是HystrixCommand,另一种是HystrixObserva ...
- python常有模块:模块、引入语法、两种执行方式、模块搜索顺序
今天主要讲了以下几点:一.模块三问.定义及分类二.import和from的语法三.文件的两种执行方式及搜索顺序四.内置函数 一.模块.import和from的语法 1.什么是模块 模块是一堆功能函 ...
- Pycharm上python运行和unittest运行两种执行方式解析
前言 经常有人在群里反馈,明明代码一样的啊,为什么别人的能出报告,我的出不了报告,为什么别人运行结果跟我的不一样啊... 这种问题先检查代码,确定是一样的,那就是运行姿势不对了,一旦导入unittes ...
- 【Shell脚本学习1】Shell简介:什么是Shell,Shell命令的两种执行方式
Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解释 ...
- 【转】shell 教程——01 Shell简介:什么是Shell,Shell命令的两种执行方式
Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解释 ...
- Shell简介:什么是Shell,Shell命令的两种执行方式
Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的.Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解释 ...
- Shell脚本的三种执行方式
Shell脚本的执行方式可以有以下几种: 方式一: ./script.sh # 利用小数点来执行 方式二: sh script.sh 或 bash script.sh # 利用bash(sh)来执 ...
- hive命令的三种执行方式
hive命令的3种调用方式 方式1:hive –f /root/shell/hive-script.sql(适合多语句) hive-script.sql类似于script一样,直接写查询命令就行 不 ...
- shell教程-001:shell简介 什么是shell,shell命令的两种执行方式
Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的. Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解 ...
随机推荐
- spring boot flyway 配置说明(摘抄)
flyway.baseline-description对执行迁移时基准版本的描述. flyway.baseline-on-migrate当迁移时发现目标schema非空,而且带有没有元数据的表时,是否 ...
- 缺jar包异常:java.lang.NoClassDefFoundError: org/springframework/core/convert/support/PropertyTypeDescriptor
严重: StandardWrapper.Throwable java.lang.NoClassDefFoundError: org/springframework/core/convert/suppo ...
- 动态创建form 完成form 提交
document.body.appendChild(jForm) won't work because jForm is not a dom element, it is a jQuery objec ...
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- sqoop2相关实例:hdfs和mysql互相导入(转)
原文地址:http://blog.csdn.net/dream_an/article/details/74936066 超详细讲解Sqoop2应用与实践 2017年07月10日 20:06:57 阅读 ...
- override virtual
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- IDEA连接数据库之后,无法自动找到表
在用IDEA连接数据库之后,在查询的时候无法自动关联出表,就如下图的提示所示: 这样看着很不舒服,按照如下设置就可以联想出表了: 点击第一个勾,关联所有: 然后就可以关联到表了
- GridControl 使用方法篇 --- 隐藏表头、隐藏Group by Box
- CSP2019心路历程
--人常说无论做什么都不要忘了初心,但如果一个人从来没有"应该"去忘了初心,又从何谈起的初心. CSP开考前,风吹在脸上,一些淡淡的回忆化作影子碎在地上:是到了一个令人感伤的路口了 ...
- BZOJ 3561: DZY Loves Math VI 莫比乌斯反演+复杂度分析
推到了一个推不下去的形式,然后就不会了 ~ 看题解后傻了:我推的是对的,推不下去是因为不需要再推了. 复杂度看似很大,但其实是均摊 $O(n)$ 的,看来分析复杂度也是一个能力啊 ~ code: #i ...