9-TaskSet测试任务集

TaskSet

官方介绍:Class defining a set of tasks that a User will execute.

也就是一个把多个task集合起来的一个类,集合内的task的用法与在user类中的并没有多大差异,例如:

from locust import TaskSet, task, FastHttpUser


class MyTask1(TaskSet):

    @task
    def task_001(self):
        self.client.get(url='/')

    @task
    def task_002(self):
        pass


class MyTask2(TaskSet):

    @task
    def task_001(self):
        pass

    @task
    def task_002(self):
        pass


class MyUser(FastHttpUser):
    tasks = [MyTask1, MyTask2]  # 权重1:1
    # tasks = {MyTask1: 1, MyTask2: 2}  # 权重1:2
posted @ 2023-09-19 18:33  威力Kami  阅读(44)  评论(0编辑  收藏  举报