通过上传文件调接口的解决思路,和处理报警异常的解决方法
import unittest
import requests
import warnings
class PostRobotPublish(unittest.TestCase):
''' 获取机器人名称 '''
def setUp(self):
self.base_url = "http://xxxxx/api/yyyy/packages/publish"
warnings.simplefilter("ignore", ResourceWarning)
def tearDown(self):
print(self.result)
def test_PostPublish(self):
"""发布流程"""
files = {'file':('jipiao',open(r'C:\Users\bqm66\Desktop\jipiao.dgs','rb'))}
print(files)
#files = {'file': open(r'C:\Users\bqm66\Desktop\jipiao.dgs', 'rb')}
# Version的值这个是需要唯一的,并且只能是增加的,不能减少
body_data = {
"Name": "jipiao",
"PublishUser": "luzhaoshan",
"Version": "1.1.1"
}
print(111)
re = requests.post(url=self.base_url, data=body_data, files=files)
self.result = re.json()
#self.assertEqual(self.result['message'], None)
self.assertEqual(self.result['errorCode'], 0)
if __name__ == '__main__':
unittest.main()
"""
Warning报警问题的解决思路
D:\python36\lib\unittest\case.py:605: ResourceWarning: unclosed file <_io.BufferedReader name='C:\Users\bqm66\Desktop\Refresh.dgs'>
testMethod()
解决办法,可以通过warnings库来忽略掉相关告警。
import warnings
warnings.simplefilter("ignore", ResourceWarning)
"""