打开模拟数据文件是路径出错
来源:6-9 unittest接口实战中mock的运用
慕运维1881141
2019-11-04
#coding = utf-8
import unittest
import os
from Base.Base_requests import request
import json
import mock
local_path = os.path.abspath('..')
#因为我的运行文件和response.json(老师的uesr_data.json)不在同一目录下
print(local_path)
host = 'http://www.imooc.com/'
def mock_response(key):
with open(local_path+"/Config/response")as f:
data = json.loads(f)
return data[key]
class imooc_test(unittest.TestCase):
def test_banner(self):
url = host+'api3/getbanneradvertver2'
data = {
'uid':'23424',
'token':'dsjfiasneifjsZEIof',
'type':'1',
'uuid':'7364'
}
mock_data = mock.Mock(return_value=mock_response('hjw'))
request.run_main = mock_data
res = request.run_main('post',url,data)
self.assertEqual(res['errorCode'],1000)
if __name__ == '__main__':
unittest.main()
报错路径:'F:\pycharm\stuta\interface_stuta_imooc/Config/response’
打印路径:F:\pycharm\stuta\interface_stuta_imooc
写回答
2回答
-
with open 后面你先把路劲拼接好,然后把那个路径打印出来,open里面别拼接的,然后去看是否有问题
012019-11-05 -
Mushishi
2019-11-04
路劲不要\这个,需要/
00
相似问题