简体   繁体   中英

Can't run locust in debug mode

Recently I switched from old locust version (0.14.2) to 1.3.1. Previously I was able to run in debug mode with command WebsiteUser().run() and it stops on all breakpoints.

When I try to run new version with the same command I get next error:

File "/home/user/PycharmProjects/my_test/venv/lib/python3.7/site-packages/locust/user/users.py", line 210, in init super(). init (*args, **kwargs) TypeError: init () missing 1 required positional argument: 'environment'

I am sure that it's possible to debug new version as previous one, but what I am doing wrong?

Environment

  • OS: Ubuntu 18.04
  • Python version: 3.7.4
  • Locust version: 1.3.1
  • Locust command line that you ran: WebsiteUser().run()
  • Locust file contents:

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')

Locust 1.0+ has more robust support for 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 for all Users and associated classes. What you'll probably want to do is:

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

You are calling

class WebsiteUser(HttpUser)

without a HttpUser argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM