使用operator.eq(expect,res1)之前expect和res1為dict型別,呼叫方法後expect為dict,res1為str,這是為什麼啊
程式碼塊如下
#coding:utf-8
from base.runmethod import RunMethod
from data.get_data import GetData
from util.operation_json import OperationJson
from util.common_util import CommonUtil
import operator
import json
class RunTest:
def __init__(self):
self.run_method = RunMethod()
self.data = GetData()
self.com_util = CommonUtil()
self.op_json = OperationJson('../dataconfig/header_value.json')
self.json_path='../dataconfig/expect_monitor_add.json'
#程式執行的
def go_on_run(self):
res = None
pass_count = []
fail_count = []
#10 0,1,2,3
#用例行數
rows_count = self.data.get_case_lines()
#遍歷所有用例進行測試
for i in range(1,rows_count):
is_run = self.data.get_is_run(i)
if is_run:
url = self.data.get_request_url(i)
method = self.data.get_request_method(i)
request_data = self.data.get_data_for_json(i)
expect = self.data.get_expect_data_for_json(i,self.json_path)
header = self.data.is_header(i)
if header == '5':
#根據關鍵字test獲取header資訊
header = self.op_json.get_data('test')
res = self.run_method.run_main(method,url,request_data,header)
# print(type(res))
#將返回結果寫入json檔案
self.op_json.write_data(res,'../dataconfig/actual_monitor_add.json')
else:
res = self.run_method.run_main(method,url,request_data)
res1 = self.op_json.get_json_data('../dataconfig/actual_monitor_add.json')
print('------呼叫operator.eq前結果---------------------------')
print(expect)
print(type(expect))
print(res)
print(type(res))
print('---------------------------------')
if operator.eq(expect,res1) == True:
self.data.write_result(i,'pass')
pass_count.append(i)
else:
res=json.dumps(res)
self.data.write_result(i,res)
fail_count.append(i)
print('-----呼叫operator.eq後結果----------------------------')
print(self.com_util.is_equal_dict(expect, res))
print(expect)
print('except',type(expect))
print(res)
print('actaul',type(res))
if __name__ == '__main__':
run = RunTest()
run.go_on_run()
執行結果:
D:\Testing_Software\Python38\python.exe D:/Code/PycharmProjects/test_rigang/main/monitor_add_test.py
<xlrd.sheet.Sheet object at 0x000001AB34E546A0>
------呼叫operator.eq前結果---------------------------
{'users': [{'id': 5796592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}, {'id': 301940, 'slug': 'ef4f2422125f', 'nickname': '盧璐說', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg', 'total_likes_count': 32964, 'total_wordage': 1789129, 'is_following_user': False}], 'total_count': 43315}
<class 'dict'>
{'users': [{'id': 5796592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}], 'total_count': 43313}
<class 'dict'>
---------------------------------
-----呼叫operator.eq後結果----------------------------
False
{'users': [{'id': 5796592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}, {'id': 301940, 'slug': 'ef4f2422125f', 'nickname': '盧璐說', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg', 'total_likes_count': 32964, 'total_wordage': 1789129, 'is_following_user': False}], 'total_count': 43315}
except <class 'dict'>
{"users": [{"id": 5796592, "slug": "86b81ed8e35c", "nickname": "\u4e54\u6c49\u7ae5", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg", "total_likes_count": 2063, "total_wordage": 356798, "is_following_user": false}, {"id": 9988193, "slug": "51b4ef597b53", "nickname": "\u8463\u514b\u5e73\u65e5\u8bb0", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg", "total_likes_count": 4337, "total_wordage": 1048047, "is_following_user": false}, {"id": 7663825, "slug": "78f970537a5e", "nickname": "\u540d\u8d35\u7684\u8003\u62c9\u718a", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg", "total_likes_count": 19514, "total_wordage": 267784, "is_following_user": false}, {"id": 6652326, "slug": "addcee2f9c78", "nickname": "\u6ca1\u6587\u5316\u7684\u91ce\u72d0\u72f8", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg", "total_likes_count": 6137, "total_wordage": 306792, "is_following_user": false}, {"id": 278, "slug": "paQcNW", "nickname": "\u9093\u54f2", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png", "total_likes_count": 1491, "total_wordage": 433989, "is_following_user": false}], "total_count": 43313}
actaul <class 'str'>
------呼叫operator.eq前結果---------------------------
{'users': [{'id': 57916592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}, {'id': 301940, 'slug': 'ef4f2422125f', 'nickname': '盧璐說', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg', 'total_likes_count': 32964, 'total_wordage': 1789129, 'is_following_user': False}], 'total_count': 43315}
<class 'dict'>
{'users': [{'id': 5796592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}, {'id': 301940, 'slug': 'ef4f2422125f', 'nickname': '盧璐說', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg', 'total_likes_count': 32964, 'total_wordage': 1789129, 'is_following_user': False}], 'total_count': 43313}
<class 'dict'>
---------------------------------
-----呼叫operator.eq後結果----------------------------
False
{'users': [{'id': 57916592, 'slug': '86b81ed8e35c', 'nickname': '喬漢童', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg', 'total_likes_count': 2063, 'total_wordage': 356798, 'is_following_user': False}, {'id': 9988193, 'slug': '51b4ef597b53', 'nickname': '董克平日記', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg', 'total_likes_count': 4337, 'total_wordage': 1048047, 'is_following_user': False}, {'id': 7663825, 'slug': '78f970537a5e', 'nickname': '名貴的考拉熊', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg', 'total_likes_count': 19514, 'total_wordage': 267784, 'is_following_user': False}, {'id': 6652326, 'slug': 'addcee2f9c78', 'nickname': '沒文化的野狐狸', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg', 'total_likes_count': 6137, 'total_wordage': 306792, 'is_following_user': False}, {'id': 278, 'slug': 'paQcNW', 'nickname': '鄧哲', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png', 'total_likes_count': 1491, 'total_wordage': 433989, 'is_following_user': False}, {'id': 301940, 'slug': 'ef4f2422125f', 'nickname': '盧璐說', 'avatar_source': 'https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg', 'total_likes_count': 32964, 'total_wordage': 1789129, 'is_following_user': False}], 'total_count': 43315}
except <class 'dict'>
{"users": [{"id": 5796592, "slug": "86b81ed8e35c", "nickname": "\u4e54\u6c49\u7ae5", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/5796592/73837104-47e5-4fe9-a5be-054bd50b06f7.jpg", "total_likes_count": 2063, "total_wordage": 356798, "is_following_user": false}, {"id": 9988193, "slug": "51b4ef597b53", "nickname": "\u8463\u514b\u5e73\u65e5\u8bb0", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/9988193/fc26c109-1ae6-4327-a298-2def343e9cd8.jpg", "total_likes_count": 4337, "total_wordage": 1048047, "is_following_user": false}, {"id": 7663825, "slug": "78f970537a5e", "nickname": "\u540d\u8d35\u7684\u8003\u62c9\u718a", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/7663825/7c28763e-002b-4e89-8dea-5b8da210ef2c.jpg", "total_likes_count": 19514, "total_wordage": 267784, "is_following_user": false}, {"id": 6652326, "slug": "addcee2f9c78", "nickname": "\u6ca1\u6587\u5316\u7684\u91ce\u72d0\u72f8", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/6652326/ba6106f4-20eb-4735-885d-561083bd4e55.jpg", "total_likes_count": 6137, "total_wordage": 306792, "is_following_user": false}, {"id": 278, "slug": "paQcNW", "nickname": "\u9093\u54f2", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/278/0778727c-c557-4ffb-929c-6ee182a58145.png", "total_likes_count": 1491, "total_wordage": 433989, "is_following_user": false}, {"id": 301940, "slug": "ef4f2422125f", "nickname": "\u5362\u7490\u8bf4", "avatar_source": "https://upload.jianshu.io/users/upload_avatars/301940/189d69dd-af7c-4290-9e2c-89e98acf3603.jpg", "total_likes_count": 32964, "total_wordage": 1789129, "is_following_user": false}], "total_count": 43313}
actaul <class 'str'>
Process finished with exit code 0
本作品採用《CC 協議》,轉載必須註明作者和本文連結