Hi,
I have developed a custom client and would like to use the host variable that can be passed on the command line when starting locust when instantiating my custom class
locust --host=http://example.com -f locustfile.py
I have interrogated the Locust object in my custom class without success.
class CustomClientLocust(Locust):
def __init__(self):
super(CustomClientLocust, self).__init__()
print str(Locust.__dict__)
hostname = Locust.host
self.client = MyCustomClient(hostname)
I can see that the options.host argument is set in the LocustRunner class, but we don't seem to have access to this in the Locust file?
Any tips on where I should be looking would be gratefully received!
Thanks!
:+1:
I have the same need but I cannot find a way to retrieve the host option. I checked main.py but apparently the options object is not stored in a location I can access from my TaskSet.
OK I found a solution. If you are subclassing Locust then you can access host using self.host.
If you are subclassing a TaskSet then you can access host using self.parent.host.
Hope this help!
Most helpful comment
OK I found a solution. If you are subclassing
Locustthen you can accesshostusingself.host.If you are subclassing a
TaskSetthen you can accesshostusingself.parent.host.Hope this help!