问题
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.
- 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?
- I also noticed that there is a
Locust
class that I can import and it seems to behave the same way as theUser
class, I didn't see any docs the would mention theLocust
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