Cannot import name 'User' from 'Locust' library

冷暖自知 提交于 2020-05-17 05:54:26

问题


I'm quite new to Locust, just starter tinkering with it a couple of days ago.

Previously I followed someone else's example which was using:

class WebsiteUser(HttpLocust):
   # Do stuff

But after reading more documentation I tried to use the User class and now I'm getting errors when I try to import the said class:

I just copy/pasted the example from the docs to make sure I didn't have any typos:

from locust import User, TaskSet, task, between

class MyTaskSet(TaskSet):
    @task
    def my_task(self):
        print("executing my_task")

class MyUser(User):
    tasks = [MyTaskSet]
    wait_time = between(5, 15)

Response:

local_1          | [2020-05-07 00:54:07,494] c8343450b35a/ERROR/stderr: File "/src/locustfile.py", line 153, in <module>
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: 
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: from locust import User, TaskSet, task, between
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: 
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: ImportError
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: :
local_1          | [2020-05-07 00:54:07,495] c8343450b35a/ERROR/stderr: cannot import name 'User'

NOTE: I am running locust inside a docker container. And if I switch back to using:

class WebsiteUser(HttpLocust):
    task_set = UserBehaviour # class UserBehaviour(TaskSet):
    wait_time = between(5.0, 9.0)

everything works fine.

This is my requirements.txt that I'm using:

locustio
influxdb==5.3.0

And I'm using the lastest version of locust docker image locustio/locust:0.14.6 So everything should be up-to-date.

  1. Do you think this is the issue with the documentation and it should be updated or did I miss something and it's my fault?
  2. I also noticed that there is a Locust class that I can import and it seems to behave the same way as the User class, I didn't see any docs the would mention the Locust class though..., does anyone know anything about it?

回答1:


The documentation at https://docs.locust.io/en/latest/ refers to locust 1.0 (currently available directly from github and as a pre-release package), where all Locust classes have been renamed User.

The current "stable" package (0.14.6) is documented here: https://docs.locust.io/en/stable/

Hopefully that explains your situation.

See the changelog for more information about changes https://docs.locust.io/en/latest/changelog.html



来源:https://stackoverflow.com/questions/61648175/cannot-import-name-user-from-locust-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!