我有一个 Pytest 脚本进行 HTTP 调用:
def test_bid_submission_send():
# Act:
response = post_requests(token, '/xxx/api/xxx/bidsubmissions/send',
setpayload_bidsubmissions_send(powerplantId))
# Assert:
assert not response.json()["error"]
assert response.status_code == 200 # Validation of status code
回复是
{"success":[],"error":[{"hpsId":10037,"powerPlant":{"name":"Saurdal","id":16606,"regionId":20,"priceArea":2,"timeSeries":null,"units":[]}}]}
我想考试失败,如果
"error":[]
有内容(在我上面的例子中就有)
如果
"success":[]
有我想通过测试的内容
我想考试失败,如果
“错误”:[...]
j = response.json()
assert len(j["error"]) == 0
如果
“成功”:[] 有内容我想通过测试
assert len(j["success"]) != 0