引发异常以根据响应数据将成功连接标记为失败

raise exceptions to flag a successful connection as a failure based upon response data

在某些情况下,我的蝗虫测试成功连接到端点,但返回的数据不是预期的。如何引发异常,以便 Locust 知道此请求应被视为失败,即使与端点的连接已成功?

使用 catch_response=True、with 块和对 resp.failure() 的调用,如此处所述:

https://docs.locust.io/en/stable/writing-a-locustfile.html#manually-controlling-if-a-request-should-be-considered-successful-or-a-failure