locust设置断言的方法

https://blog.csdn.net/panyu881024/article/details/80146088


这里同样以测试百度首页为例。

catch_response = True :布尔类型,如果设置为 True, 允许该请求被标记为失败。

通过 client.get() 方法发送请求,将整个请求的给 response, 通过 response.status_code 得请求响应的 HTTP 状态码。如果不为 200 则通过 response.failure(‘Failed!’) 打印失败!

例子:

def baidu_index(self):

  a=self.client.get('/', catch_response = True)

  if a.status_code == 201:
    a.success()
  else:
    a.failure("Got wrong response")

猜你喜欢

转载自www.cnblogs.com/kaibindirver/p/11772378.html
今日推荐