【转载】locust性能测试3
#coding=utf-8 from locust import HttpLocust,TaskSet,task import queue import random class test_taskset(TaskSet): @task def register(self): try: email=self.locust.emailqueue.get() #获取队列里的数据 print(email) except queue.Empty: #队列取空后,直接退出 print('no data exist') exit(0) print('当前注册的邮箱:%s' %email) body={"user":{"password":"123123","user_email":email,"full_name":"111"},"store_id":"7090","client_id":"9xqgzfbgg3myal2ikn7mls9vjqcj34j","client_secret":"k6fqamfib6x9rx4avrb2w63g9qvguo6"} self.client.post('/api/v2/signup',json=body) #post方法发送请求 class test_run(HttpLocust): host='https://trybindo.com' task_set=test_taskset # 生成测试手机号 emaildata=[str(1381212000+i)+'@bindo.com' for i in range(100)] #添加到队列 emailqueue=queue.Queue() for i in emaildata: emailqueue.put_nowait(i) if __name__=='__main__': import os os.system('locust -f locustpialiangzhuce.py')