解决Locust1.2.2脚本报错AttributeError: ‘UserBehavior‘ object has no attribute ‘locust‘的问题

问题:

locust进行接口性能测试,使用之前的locust脚本模板报错:AttributeError: 'UserBehavior' object has no attribute 'locust'

解决Locust1.2.2脚本报错AttributeError: ‘UserBehavior‘ object has no attribute ‘locust‘的问题

原因分析:

打开官方文档查看:https://docs.locust.io/en/latest/changelog.html#locust-class-renamed-to-user

解决Locust1.2.2脚本报错AttributeError: ‘UserBehavior‘ object has no attribute ‘locust‘的问题

发现是自己忽略了1.0到1.0.1中“The locust attribute on TaskSet instances has been renamed to user.”TaskSet实例上的locust属性被重命名为user。

解决方法:

将脚本中TaskSet实例上的locust属性名全部替换为user。

解决Locust1.2.2脚本报错AttributeError: ‘UserBehavior‘ object has no attribute ‘locust‘的问题

参考博客:Locust1.*版本主要变化以及脚本使用模版