首页 > 其他 > 详细

接口测试脚本实践记录(六)

时间:2018-12-16 21:03:43      阅读:137      评论:0      收藏:0      [点我收藏+]

六 与数据库对比

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!