无法在调试模式下 运行 locust

Can't run locust in debug mode

最近我从旧的 locust 版本 (0.14.2) 切换到 1.3.1。以前我可以使用命令 WebsiteUser().运行() 在调试模式下 运行,它会在所有断点处停止。

当我尝试使用相同的命令 运行 新版本时,出现下一个错误:

文件“/home/user/PycharmProjects/my_test/venv/lib/python3.7/site-packages/locust/user/users.py”,第 210 行,在 init 中 super().init(*args, **kwargs) 类型错误:init() 缺少 1 个必需的位置参数:'environment'

我确定可以像以前一样调试新版本,但我做错了什么?

环境

locustfile.py:

class UserBehaviour(MyTask):

    @task
    def task_one(self):
        self.action_one()


class WebsiteUser(HttpUser):
    conf = Config()
    host = conf.host
    tasks = [UserBehaviour]
    wait_time = between(0.5, 1.5)

if __name__ == "__main__":
    WebsiteUser().run()

my_task.py:

class MyTask(BaseTaskSet):

    def action_one(self):
        self.client.get('dummy_path')

您正在打电话

class WebsiteUser(HttpUser)

没有 HttpUser 参数。

Locust 1.0+ 为所有 Users 和关联的 类 提供了对 using Locust as a library. It enables a lot more flexibility and customization in using Locust but there were a number of breaking changes to achieve this (one reason for the 1.0 designation). What you're hitting is Locust now requires an Environment 更强大的支持。您可能想要做的是:

if __name__ == "__main__":
    from locust.env import Environment
    my_env = Environment(user_classes=[WebsiteUser])
    WebsiteUser(my_env).run()