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")

    sys.exit(0)

posted @ 2019-10-31 17:06  凯宾斯基  阅读(1591)  评论(0编辑  收藏  举报