• python locust--Setups, Teardowns, on_start, and on_stop .(用例执行前执行一次请求啥的)


    创建一个locust测试脚本,如下:

    from locust import HttpLocust, TaskSet, task


    class UserBehavior(TaskSet):
    def setup(self):
    print('task setup')

    def teardown(self):
    print('task teardown')

    def on_start(self):
    # 虚拟用户启动Task时运行
    print('start')

    def on_stop(self):
    # 虚拟用户结束Task时运行
    print('end')

    @task(2)
    def index(self):
    self.client.get("/")

    @task(1)
    def profile(self):
    self.client.get("/profile")


    class WebsiteUser(HttpLocust):
    def setup(self):
    print('locust setup')

    def teardown(self):
    print('locust teardown')
    task_set = UserBehavior
    min_wait = 5000
    max_wait = 9000


    if __name__ == '__main__':
    pass
    说明:

    Locust类有setup和teardown,TaskSet类有setup、teardown、on_start、on_stop。

    每次启动locust时运行setup方法,退出时运行teardown方法,locust执行TaskSet时运行TaskSet的setup方法,退出时运行teardown方法,每个虚拟用户执行操作时运行on_start方法,退出时执行on_stop方法,运行上面的脚本,执行顺序如下:

    执行顺序如下:

    Locust setup

    TaskSet setup

    TaskSet on_start

    TaskSet tasks

    TaskSet on_stop

    TaskSet teardown

    Locust teardown
    ————————————————
    版权声明:本文为CSDN博主「梦入玄机」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_36255988/article/details/82622044

  • 相关阅读:
    POJ 2996 Help Me with the Game (模拟)
    PCL系列——怎样逐渐地配准一对点云
    sublime text3同时编辑多行
    博客搬家
    将博客搬至CSDN
    centos7用xshell可以连接, xftp连接失败!(墙裂推荐)
    重启ssh服务出现Redirecting to /bin/systemctl restart sshd.service
    重装wordpress
    ubuntu 16.04 启用root用户方法
    Ubuntu创建新用户并增加管理员权限(授权有问题)
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/11774651.html
Copyright © 2020-2023  润新知