1. # -*- coding: utf-8 -*-
2. # @Time : 2021/5/2
3. # @Author : 大海
4.
5. import os
6. from locust import User, SequentialTaskSet, task, constant
7.
8.
9. class MyTask(SequentialTaskSet):
10. wait_time = constant(1)
11.
12. # 按照my_task1,my_task2,my_task3,my_task4的顺序执行
13. @task
14. def my_task1(self):
15. print("用户行为1")
16.
17. @task
18. def my_task2(self):
19. print("用户行为2")
20.
21. @task
22. def my_task3(self):
23. print("用户行为3")
24.
25. @task
26. def my_task4(self):
27. print("用户行为4")
28.
29.
30. class MyUser(User):
31. wait_time = constant(1)
32. tasks = [MyTask]
33.
34.
35. if __name__ == '__main__':
36. file_path = os.path.abspath(__file__)
37. os.system(f'locust -f {file_path} --web-host=127.0.0.1')