0

my problem is that i am trying to use locust for the first time and i copied the basic code from their website https://docs.locust.io/en/stable/quickstart.html

this is the code that they have given

from locust import HttpUser, task, between
import random

class WebsiteUser(HttpUser):
    wait_time = between(5, 9)

    @task(2)
    def index(self):
        self.client.get("/")
        self.client.get("/ajax-notifications/")

    @task(1)
    def view_post(self):
        post_id = random.randint(1, 10000)
        self.client.get("/post?id=%i" % post_id, name="/post?id=[post-id]")

    def on_start(self):
        """ on_start is called when a User starts before any task is scheduled """
        self.login()

    def login(self):
        self.client.post("/login", {"username":"ellen_key", "password":"education"})

This is the path to my locustfile.py

E:\work\wipro\work\locust_training\locustfile.py

To run the locustfile.py i type locust in terminal

E:\work\wipro\work\locust_training>locust

The error that it throws is

[2020-05-23 14:44:25,916] DESKTOP-LQ261OQ/INFO/locust.main: Starting web monitor at http://:8089
Traceback (most recent call last):
  File "e:\setup\python\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\setup\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "E:\setup\python\Scripts\locust.exe\__main__.py", line 9, in <module>
  File "e:\setup\python\lib\site-packages\locust\main.py", line 236, in main
    web_ui = environment.create_web_ui(
  File "e:\setup\python\lib\site-packages\locust\env.py", line 144, in create_web_ui
    self.web_ui = WebUI(self, host, port, auth_credentials=auth_credentials, tls_cert=tls_cert, tls_key=tls_key)
  File "e:\setup\python\lib\site-packages\locust\web.py", line 79, in __init__
    app = Flask(__name__)
  File "e:\setup\python\lib\site-packages\flask\app.py", line 558, in __init__
    self.add_url_rule(
  File "e:\setup\python\lib\site-packages\flask\app.py", line 66, in wrapper_func
    return f(self, *args, **kwargs)
  File "e:\setup\python\lib\site-packages\flask\app.py", line 1216, in add_url_rule
    self.url_map.add(rule)
  File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1562, in add
    rule.bind(self)
  File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 711, in bind
    self.compile()
  File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 767, in compile
    self._build = self._compile_builder(False)
  File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1128, in _compile_builder
    return self.BuilderCompiler(self).compile(append_unknown)
  File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1119, in compile
    co = types.CodeType(*code_args)
TypeError: code() takes at least 14 arguments (13 given)

I searched for the same but was not able to find any specific solution I even tried to copy any locust code i was able to find but that was also not helpful as in one way or other either this error came or some other

Can anyone help with this

What should I do next

Any help will be appreciated

And Thanks in Advance

Dev Chahal
  • 23
  • 5
  • You probably want to do `python E:\work\wipro\work\locust_training\your_script.py` no? – Torxed May 23 '20 at 09:29
  • no on there website they have said that u have to write the name for a locust file as locustfile.py and just write locust in cmd to run your locust file – Dev Chahal May 23 '20 at 09:33

2 Answers2

0

Well i guess if anyone else encounters this error you can try this: I updated all the libraries that i have installed to their latest versions You can use the following code to do so and after that it worked for me and maybe it will work for you too

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)

Good luck

Dev Chahal
  • 23
  • 5
  • Probably Locust's minimum required flask version should be updated, because this workaround should not be needed. I added a ticket https://github.com/locustio/locust/issues/1394 – Cyberwiz May 25 '20 at 07:08
0

I suspect that the problem was that locust's requirements didnt specify a recent version of flask (or maybe its dependency in turn, Werkzeug). So if you happened to have an old version installed (but recent enough for locust's dependency to be fulfilled), locust would try to use it but fail.

We have updated this dependency now (in Locust 1.0.2), so hopefully this should not happen to anyone again.

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40
  • I had the latest version of locust and can you also help with one more doubt like i tried to run locustfile and what happenes is that if i specify like 300 requests then it just keeps on running even after 300 requests i uses the time limit to make the test run for 1 minute but it still sends more than 300 requests Is there any specific way with which i can direct locust to stop like when it reaches exact 300 requests. something like this is possible? Cause in jmeter if i specified 300 requests then it send 300 requests. I want to do the same thing with locust. – Dev Chahal May 27 '20 at 09:32
  • What I meant was we updated locust after this ticket was created (so you probably had 1.0.1) Stopping after a specific number of requests is not supported out of the box atm, see https://github.com/locustio/locust/issues/1085 (might change though) – Cyberwiz May 27 '20 at 12:28