六 与数据库对比
import pymssql def compare_expected_vs_db(): diff_list = [] # 存储不一致的代码 with pymssql.connect(server=‘192.168.1.1‘, user=‘test‘, password=‘123456‘,database=‘db‘) as myconnect: with myconnect.cursor(as_dict=True) as cursor: cursor.execute("SELECT top 10 code,content FROM [db].[dbo].[table] where isvalid = 1 and IsDeleted =0") for row in cursor: code, actual = row[‘code‘], row[‘content‘] expected = result_of_3api(stockcode) # 数据源拼接结果 if actual != expected: # 预期实际对比 print(‘代码:%s\n实际结果:%s\n预期结果:%s‘ % (code, actual , expected)) diff_list.append(code) else: print(code, ‘一致‘) if diff_list: print(‘不一致的列表:‘, diff_list) else: print(‘对比结果:数据全部一致‘)
原文地址:https://www.cnblogs.com/dinghanhua/p/10127941.html
时间: 2024-09-28 07:42:45