loust 多接任务和顺序执行
locust 多任务执行,task() 括号里的数值越大,执行频率越高
代码如下:
from locust import HttpUser, TaskSet, task,os
class MyTask(TaskSet):
@task(1)
def get_weather(self):
response1 = self.client.get("/api/daygas.php?mag='beijing'&b=1",name="quer_weather")
print(response1.text)
@task(2)
def get_car(self):
response2 = self.client.get("/api/picture.php?msg='汽车'", name="query_car")
print(response2.text)
class WebsiteUser(HttpUser):
tasks = [MyTask]
min_wait = 5000
max_wait = 9000
if __name__ == "__main__":
os.system("locust -f MixInterfaceTest.py --host=http://api.wpbom.com")
locust 顺序执行接口测试
代码如下:
from locust import HttpUser, TaskSet, task,os,SequentialTaskSet
#继承SequentialTaskSet 两个接口顺序执行,@task 权重就没用了
class MyTask(SequentialTaskSet):
@task
def get_weather(self):
response1 = self.client.get("/api/daygas.php?mag='beijing'&b=1", name="quer_weather")
print(response1.text)
@task
def get_car(self):
response2 = self.client.get("/api/picture.php?msg='汽车'", name="query_car")
print(response2.text)
class WebsiteUser(HttpUser):
tasks = [MyTask]
min_wait = 5000
max_wait = 9000
if __name__ == "__main__":
os.system("locust -f SeqTest.py --host=http://api.wpbom.com")