目录
一个locustfile中有多个User
使用--class-picker指定执行
小结
from locust import task, HttpUser
class User01(HttpUser):
weight = 3 # 权重
host = 'https://www.baidu.com'
@task
def user_01_task(self):
self.client.get(url='/', name='user_01_task')
class User02(HttpUser):
weight = 1 # 权重
host = 'https://www.qq.com'
@task
def user_02_task(self):
self.client.get(url='/', name='user_02_task')
host
,运行时就可以不填hostweight
,和上一节task设置到权重一样,运行时user分配比重按照3:1执行$ locust -f locustfiles/multiple_user.py --class-picker
$ locust -f locustfiles/multiple_user.py --class-picker User02 User01 --headless -u 20 -r 20 -t 5s
[2023-07-28 12:17:00,956] HUAWEI-MateBook-X-Pro.local/INFO/locust.runners: Ramping to 20 users at a rate of 20.00 per second
[2023-07-28 12:17:00,957] HUAWEI-MateBook-X-Pro.local/INFO/locust.runners: All users spawned: {"User01": 15, "User02": 5} (20 total users)
weight
属性修改它们的执行比重locust -h
来查看以下是我收集到的比较好的学习教程资源,虽然不是什么很值钱的东西,如果你刚好需要,可以评论区,留言【777】直接拿走就好了
各位想获取资料的朋友请点赞 + 评论 + 收藏,三连!
三连之后我会在评论区挨个私信发给你们~