import time from locust import HttpUser, task, between,tag class QuickstartUser(HttpUser): wait_time = between(1, 5) @task(3) @tag("tag1") def hello_world(self): self.client.get("https://haokan.baidu.com/?sfrom=baidu-top") self.client.get("https://h.xinhuaxmt.com/vh512/share/12023723?d=134d889") @task(3) def view_items(self): for item_id in range(2300,2302,1): self.client.get("https://music.taihe.com/songlist?id={item_id}") time.sleep(1) @task def hello_world1(self): self.client.get("https://ai.hanghang.com/page/4649915") self.client.get("https://www.cnblogs.com/thisiswhy/p/18202897")
- 进入locustfile1.py 的同级目录下,执行该命令即可运行locustfile1.py
locust -f locustfile1.py -T tag1 #此命令只会运行tag1下的测试方法
- @task(3) #这个3指的是运行的权重, 修改权重可修改执行的接口的数量比例,执行的命令是 locust -f locustfile1.py
注意,蓝色框和红色框对应的方法的tag都是3,为啥是1:2,是因为 view_items 里面有个循环,可取值 2300,2301,不包括2303.
标签:task,get,self,locust,tag,https From: https://www.cnblogs.com/123anqier-blog/p/18206090