• 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
    实际结果:%s
    预期结果:%s' % (code, actual , expected))
                            diff_list.append(code)
                        else:
                            print(code, '一致')
    
        if diff_list:
             print('不一致的列表:', diff_list)
        else:
             print('对比结果:数据全部一致')
  • 相关阅读:
    ES6-11学习笔记--正则表达式的扩展
    ES6-11学习笔记--字符串的扩展
    ES6-11学习笔记--Map
    ES6-11学习笔记--Set
    ES6-11学习笔记--Symbol
    final
    MySQL
    爬虫1
    laravel
    HTML学习
  • 原文地址:https://www.cnblogs.com/dinghanhua/p/10127941.html
Copyright © 2020-2023  润新知