# *_*coding:utf-8 *_*
# @Author : zyb
from locust import TaskSet, task, FastHttpUser, between, events
# 定义任务集类
@events.request.add_listener
def on_request(request_type, name, context, response, exception, **kwargs):
if request_type == "GET" and name == "测试":
print('判断执行')
@events.test_start.add_listener
def get_test_start( **kwargs):
print('这个函数整个压测只执行一次')
@events.test_stop.add_listener
def aa(**kwargs):
print('测试时,点击stop后执行的程序,和test_stopping差别不大')
class AAA(TaskSet):
@task
def task_get(self):
url = '/GetTztAll/'
self.client.get(url=url, name='测试')
@task
def task_post(self):
url = '/GetTztAll/'
self.client.post(url=url, name='测试')
# 定义用户类
class WebsiteUser(FastHttpUser):
tasks = [AAA]
wait_time = between(1, 2)
if __name__ == "__main__":
import os
file_path = os.path.abspath(__file__)
os.system(f"locust -f {file_path} --host=http://127.0.0.1:8000")