使用jsonpath断言
import requests from jsonpath import jsonpath def test_post_json(self): payload = { "level": 1, "name": "xuefeifei" } r = requests.post("https://httpbin.testing-studio.com/post", json=payload) print(r.json()) #assert r.json()["json"]["level"] == 1 #print(jsonpath(r.json(),'$..level')) assert jsonpath(r.json(),'$..level')[0] == 1