zl程序教程

您现在的位置是:首页 >  后端

当前栏目

locust设置断言的方法

方法 设置 断言 Locust
2023-09-27 14:25:19 时间

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)