I'm quite new to Locust
, just started tinkering with it a couple of days ago.
To quick start, i was following someone else example as below,
file : locustfile.py
import random
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before
any task is scheduled
"""
self.login()
def login(self):
self.client.post("/login",
{"username":"ellen_key",
"password":"education"})
@task(2)
def index(self):
self.client.get("/")
@task(1)
def profile(self):
self.client.get("/profile")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
When i run locust from the current directory, i am getting the below exception,
Traceback (most recent call last):
File "/usr/local/bin/locust", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/locust/main.py", line 113, in main
docstring, user_classes = load_locustfile(locustfile)
File "/usr/local/lib/python3.6/dist-packages/locust/main.py", line 77, in load_locustfile
imported = __import_locustfile__(locustfile, path)
File "/usr/local/lib/python3.6/dist-packages/locust/main.py", line 53, in __import_locustfile__
return source.load_module()
File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 823, in load_module
File "<frozen importlib._bootstrap_external>", line 682, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/koushic/kk-ldl/locust/locustfile.py", line 19, in <module>
class WebsiteUser(HttpLocust):
File "/usr/local/lib/python3.6/dist-packages/locust/util/deprecation.py", line 23, in __new__
raise ImportError(deprecation_message)
ImportError: The HttpLocust class has been renamed to HttpUser in version 1.0. For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0
Could someone help me to understand the issue here.
Python 3.6.9
pip 20.1.1
Just check the last line of the error message:
ImportError: The HttpLocust class has been renamed to HttpUser in version 1.0. For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0
If you're lucky all you'll need to do is change these two lines:
from locust import HttpUser, TaskSet, task
class WebsiteUser(HttpUser):