def test_negative_multi(self, data_namedtuple): """ 1.两个负数相乘 :return: """ print("\nrunning test method:{}".format(inspect.stack()[0][3])) # 获取两个负数相乘的结果 case_id = data_namedtuple.case_id msg = data_namedtuple.title l_data = data_namedtuple.l_data r_data = data_namedtuple.r_data except_result = data_namedtuple.expected real_result = MathOperation( l_data, r_data).multiply() # 类+() 是对象 用对象调用类中的实例multiply() # 验证实际结果与预期是否一致 ws.cell(row=case_id + 1, column=6, value=real_result) # 将实际结果写入Excel # except_result = 4 # 不需要手动添加期待值 # 第一种方法使用条件判断不能实现功能 # if real_result == except_result: # print("pass") # else: # print("fail") try: self.assertEqual(except_result, real_result, msg="测试{}失败".format(msg)) except AssertionError as e: print("这里需要使用日志器来记录日志") print("具体异常为:{}".format(e)) ws.cell(row=case_id + 1, column=7, value="Fail") self.assertRaises(TypeError) # assertRaises可以直接断言异常 # raise关键字是将某个异常主动抛出 raise e else: ws.cell(row=case_id + 1, column=7, value="Pass")
def test_neg_pos_multi(self): """ 4.一个正数和一个负数相乘 :return: """ data_namedtuple = test_list.pop(0) case_id = data_namedtuple.case_id msg = data_namedtuple.title l_data = data_namedtuple.l_data r_data = data_namedtuple.r_data except_result = data_namedtuple.expected real_result = MathOperation( l_data, r_data).multiply() # 类+() 是对象 用对象调用类中的实例multiply() # 验证实际结果与预期是否一致 ws.cell(row=case_id + 1, column=6, value=real_result) # 将实际结果写入Excel # except_result = 4 # 不需要手动添加期待值 # 第一种方法使用条件判断不能实现功能 # if real_result == except_result: # print("pass") # else: # print("fail") try: self.assertEqual(except_result, real_result, msg="测试{}失败".format(msg)) except AssertionError as e: print("这里需要使用日志器来记录日志") print("具体异常为:{}".format(e)) ws.cell(row=case_id + 1, column=7, value="Fail") # raise关键字是将某个异常主动抛出 raise e else: ws.cell(row=case_id + 1, column=7, value="Pass")
def test_negative_multi(self, data_namedtuple): """ 1.两个负数相乘 :return: """ # print("\nrunning test method:{}".format(inspect.stack()[0][3])) do_log.info("\nrunning test method:{}".format(inspect.stack()[0][3])) # 获取两个负数相乘的结果 case_id = data_namedtuple.case_id msg = data_namedtuple.title l_data = data_namedtuple.l_data r_data = data_namedtuple.r_data except_result = data_namedtuple.expected real_result = MathOperation( l_data, r_data).multiply() # 类+() 是对象 用对象调用类中的实例multiply() # 将实际结果写入Excel # run_success_msg = TestMulti("msg","success_result") run_success_msg = do_config("msg", "success_result") # run_fail_msg = TestMulti("msg", "fail_result") run_fail_msg = do_config("msg", "fail_result") try: self.assertEqual(except_result, real_result, msg="测试{}失败".format(msg)) except AssertionError as e: # print("这里需要使用日志器来记录日志") # print("具体异常为:{}".format(e)) do_log.error("具体异常为:{}".format(e)) # ws.cell(row=case_id+1,column=7,value="Fail") # self.test_obj.write_result(row=case_id+1,actual=real_result,result="Fail") # self.test_obj.write_result(row=case_id+1,actual=real_result,result=self.config("msg","fail_result")) do_excel.write_result(row=case_id + 1, actual=real_result, result=do_config("msg", "fail_result")) # self.assertRaises(TypeError) # assertRaises可以直接断言异常 # raise关键字是将某个异常主动抛出 raise e else: # ws.cell(row=case_id+1,column=7,value="Pass") # self.test_obj.write_result(row=case_id+1,actual=real_result,result="Pass") do_excel.write_result(row=case_id + 1, actual=real_result, result=do_config("msg", "success_result"))