from deepdiffimport DeepDiff
'''
pip install deepdiff
最好用的断言包'''
def deepdiffs(tag,old,new):
if tag:
result = DeepDiff(old,new)
return "没有加字段黑名单的比较结果 %s " % result
else:
# 使用exclude_paths加入不校验字段
result = DeepDiff(old,new,exclude_paths = {"root[0]['bloodVolume']['startTime']"})
return "加了字段黑名单的比较结果 %s " % result
if __name__ =='__main__':
old = [{'bloodVolume':{'startTime':'2022-03-30','upDown':'10','unit':[1,2,5]}}]
new = [{'bloodVolume':{'startTime':'2022-03-31','upDown':'10','unit':[1,2,5]}}]
print(deepdiffs(1,old,new))
print(deepdiffs(0,old,new))