- 普通方法
# 预期结果
expected = {'username':'kaishui'}
# 实际结果
result={
'code': 1 ,
'username':'kaishui',
'token':'ihbedvbwejhvkjvberkjvbkjgkesjvbbje'
}
def assert_dict(expected, result):
for key in expected:
if (key in result) & (result[key]==expected[key]):
print('测试通过')
else:
raise Exception('断言不通过')
assert_dict(expected,result)
- set方法
# 预期结果
expected = {'username':'kaishui'}
# 实际结果
result={
'code': 1 ,
'username':'kaishui',
'token':'ihbedvbwejhvkjvberkjvbkjgkesjvbbje'
}
expected_set = set(expected.items())
result_set = set(result.items())
print(expected_set.issubset(result_set))