根据业务场景,本人写了一个通用的动态断言方法,支持value,{key:value},{key:正则表达式},方法如下
# coding=utf-8
import re
from app_execution.allFunction import allFunction
class TestResult(object):
def testcase(self, result, assertdata): # 根据respcode和message正则断言
testresult ='0'
if (result == None or assertdata == None): # 如果断言规则是空的
testresult = '1'
if isinstance(assertdata, str): # 如果断言规则是字符串
assert_respcode_result = re.search(assertdata, result['respCode'], re.I | re.M)
assert_message_result = re.search(assertdata, result['message'], re.I | re.M)
if assert_respcode_result or assert_message_result:
testresult = '1'
else:
testresult = TestResult().assert_key(assertdata, result)
return testresult
def assert_key(self, assert_data, result):#递归断言
testresult &