SeldomQA / seldom

Seldom automation testing framework based on unittest
https://seldomqa.github.io/
Apache License 2.0
803 stars 328 forks source link

【bug】 diff_json 对比方法错误 #197

Closed defnngj closed 1 year ago

defnngj commented 1 year ago
a = {"error":{"code":"","message":""},"result":{"booking_list":[{}],"Total":1},"success": True}
b = {"error":{"code":"","message":""},"result":{"booking_list":[{}],"Total":1},"success":True}

from seldom.utils import diff_json
diff_json(a, b)
/Users/zhiheng.hu/klpro/gitlab/klook_autoapitest/t_sample.py
Traceback (most recent call last):
  File "/Users/zhiheng.hu/klpro/gitlab/klook_autoapitest/t_sample.py", line 27, in <module>
    diff_json(a, b)
  File "/Users/zhiheng.hu/.local/share/virtualenvs/klook_autoapitest-4W43aEPJ/lib/python3.9/site-packages/seldom/utils/diff.py", line 34, in diff_json
    diff_json(response_data[key], assert_data[key], exclude)
  File "/Users/zhiheng.hu/.local/share/virtualenvs/klook_autoapitest-4W43aEPJ/lib/python3.9/site-packages/seldom/utils/diff.py", line 34, in diff_json
    diff_json(response_data[key], assert_data[key], exclude)
  File "/Users/zhiheng.hu/.local/share/virtualenvs/klook_autoapitest-4W43aEPJ/lib/python3.9/site-packages/seldom/utils/diff.py", line 44, in diff_json
    response_data = sorted(response_data, key=lambda x: x[list(response_data[0].keys())[0]])
  File "/Users/zhiheng.hu/.local/share/virtualenvs/klook_autoapitest-4W43aEPJ/lib/python3.9/site-packages/seldom/utils/diff.py", line 44, in <lambda>
    response_data = sorted(response_data, key=lambda x: x[list(response_data[0].keys())[0]])
IndexError: list index out of range
defnngj commented 1 year ago

问题二

a环境返回

[
    {
        "content":"1",
        "desc":"aaaa"
    },
    {
        "content":"1",
        "desc":"bbbb"
    }
]

b环境返回

[
    {
        "content":"1",
        "desc":"bbbb"
    },
    {
        "content":"1",
        "desc":"aaaa"
    }
]

第一个字段相同,用第二个字段排序!

defnngj commented 1 year ago

seldom 3.3.0 解决