def test_case(self,case): #传入测试数据整体 global result method = case['Method'] url = case['Url'] param = eval(case['Params']) # params 本身是一个字符串 expected_result = eval(case['ExpectedResult']) # 本身也是一个字符串 # 发起测试 self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'], case['CaseId'], case['Title'])) self.my_log.info('参数是{}'.format(param)) # 实例化请求 res = HttpRequest() resp = res.http_request(method,url,param,cookies=None) print('实际结果是{}'.format(resp.json())) # 对比 try: self.assertEqual(expected_result,resp.json()) result = 'pass' self.my_log.info('该条用例通过') except Exception as e: result = 'failed' self.my_log.info('该条用例失败,{}'.format(e)) raise e finally: final_result = result # 写会实际结果与是否通过 self.do_exl.write_back(case['CaseId']+1,8,resp.text) # TODO:注意是写回text,不能写回json self.do_exl.write_back(case['CaseId']+1,9,final_result) self.my_log.info('写入数据完毕') self.my_log.info('本条用例结束')
def test_case(self, case): global result #声明全局变量 method = case['Method'] url = case['Url'] param = eval(case['Params']) # print(param) expected = eval(case['ExpectedResult']) # # 查找替换mobilephone # if case['Params'].find('normal_phone') != -1: # param['mobilephone']=getattr(GetData,'normal_phone') # # print(param) # 调用正则函数替换mobilephone,pwd:TODO:只替换Params param = eval(get_data.replace(case['Params'])) #发起测试 # print('-------正在测试{}模块里面第{}条测试用例:{}'.format(case['Module'],case['CaseId'],case['Title'])) self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'], case['CaseId'], case['Title'])) self.my_log.info('参数是:{}'.format(param)) res = HttpRequest() #实例化 resp = res.http_request(method, url, param, cookies=None) print('实际结果:{}'.format(resp.json())) #http发送请求拿到的实际返回值 #对比结果 try: self.assertEqual(expected, resp.json()) result = 'pass' self.my_log.info('该条测试用例通过') # print('该条测试用例通过') except AssertionError as e: result = 'failed' self.my_log.error('该条测试用例不通过:'.format(e))
def test_case(init_api): #传入测试数据整体 global result method = init_api[0]['Method'] url = init_api[0]['Url'] param = eval(init_api[0]['Params']) # params 本身是一个字符串 expected_result = eval(init_api[0]['ExpectedResult']) # 本身也是一个字符串 # 发起测试 init_api[2].info('正在执行{}模块第{}条用例:{}'.format(init_api[0]['Module'], init_api[0]['CaseId'], init_api[0]['Title'])) init_api[2].info('参数是{}'.format(param)) # 实例化请求 res = HttpRequest() resp = res.http_request(method, url, param, cookies=None) print('实际结果是{}'.format(resp.json())) # 对比 try: assert expected_result == resp.json() result = 'pass' init_api[2].info('该条用例通过') except Exception as e: result = 'failed' init_api[2].info('该条用例失败,{}'.format(e)) raise e MyLog().info('本条用例结束')
def test_case(self,case): global result #声明全局变量 method=case['Method'] url=case['Url'] param=eval(case['Params']) # print(param) expected=eval(case['ExpectedResult']) #发起测试 # print('-------正在测试{}模块里面第{}条测试用例:{}'.format(case['Module'],case['CaseId'],case['Title'])) self.my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'],case['CaseId'],case['Title'])) self.my_log.info('参数是:{}'.format(param)) res=HttpRequest() #实例化 resp=res.http_request(method,url,param,cookies=None) print('实际结果:{}'.format(resp.json()))#http发送请求拿到的实际返回值 #对比结果 try: self.assertEqual(expected,resp.json()) result='pass' self.my_log.info('该条测试用例通过') # print('该条测试用例通过') except AssertionError as e: result='failed' self.my_log.error('该条测试用例不通过:'.format(e))
'''case 是上面传的测试用例数据''' my_log = init_api global result #声明全局变量 method=case['Method'] url=case['Url'] param=eval(case['Params']) # print(param) expected=eval(case['ExpectedResult']) # 调用正则函数替换mobilephone,pwd:TODO:只替换Params param=eval(replace(case['Params'])) #发起测试 # print('-------正在测试{}模块里面第{}条测试用例:{}'.format(case['Module'],case['CaseId'],case['Title'])) my_log.info('正在执行{}模块第{}条用例:{}'.format(case['Module'],case['CaseId'],case['Title'])) my_log.info('参数是:{}'.format(param)) res=HttpRequest() #实例化 resp=res.http_request(method,url,param,cookies=None) print('实际结果:{}'.format(resp.json()))#http发送请求拿到的实际返回值 # print('测试',type(resp.json()['code'])) #对比结果 try: assert expected == resp.json() result='pass' my_log.info('该条测试用例通过') # print('该条测试用例通过') except AssertionError as e: result='failed' my_log.error('该条测试用例不通过:'.format(e)) # print('该条测试用例不通过:{}'.format(e)) @pytest.mark.parametrize('case',recharge_data)