python接口测试-项目实践(六) 实际结果与预期结果对比之 数据源与数据库对比...

六 与数据库对比

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(code)  # 数据源拼接结果

                    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

你可能感兴趣的:(python接口测试-项目实践(六) 实际结果与预期结果对比之 数据源与数据库对比...)