I'm currently passing custom parameters to my load test using environment variables. For example, my test class looks like this:
from locust import HttpLocust, TaskSet, task import os class UserBehavior(TaskSet): @task(1) def login(self): test_dir = os.environ['BASE_DIR'] auth=tuple(open(test_dir + '/PASSWORD').read().rstrip().split(':')) self.client.request( 'GET', '/myendpoint', auth=auth ) class WebsiteUser(HttpLocust): task_set = UserBehavior
Then I'm running my test with:
locust -H https://myserver --no-web --clients=500 --hatch-rate=500 --num-request=15000 --print-stats --only-summary
Is there a more locust
way that I can pass custom parameters to the locust
command line application?
HttpUser classThis class creates a client attribute on instantiation which is an HTTP client with support for keeping a user session between requests. abstract = True. If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test.
The wait_time attribute It's used to determine for how long a simulated user will wait between executing tasks. Locust comes with a few built in functions that return a few common wait_time methods. The most common one is between .
How to run a load test in Locust. The key –host http://localhost:3000 specifies the host on which Locust should be run (the corresponding field is filled in by default, but this value can be changed). Specify the values: in our example, Number of users = 10 and Spawn rate = 2. Next, use Start swarming to run the test.
You could use like env <parameter>=<value> locust <options>
and use <parameter>
inside the locust script to use its value
E.g., env IP_ADDRESS=100.0.1.1 locust -f locust-file.py --no-web --clients=5 --hatch-rate=1 --num-request=500
and use IP_ADDRESS inside the locust script to access its value which is 100.0.1.1 in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With