1. 程式人生 > >接口測試腳本實踐記錄(六)

接口測試腳本實踐記錄(六)

(六) password != else expected ali connect lis expec

六 與數據庫對比

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(對比結果:數據全部一致
)

接口測試腳本實踐記錄(六)