with self.client.post(url,headers=headers,json=query,catch_response=True)as response:if json.loads(response.text)['code']=='0':
response.success()else:
response.failure('Failed!')
最后找到这个断言,非常好用,完美解决了问题
from json import JSONDecodeError
with self.client.post(url,headers=headers,json=query,catch_response=True)as response:if response.status_code !=200:
response.failure("Did not get expected status code")try:if json.loads(response.text)['code']!='0':
response.failure("Did not get expected value in status")except JSONDecodeError:
response.failure("Response could not be decoded as JSON")except KeyError:
response.failure("Response did not contain expected key 'status'")