Locust: "Order of events" clarification

Created on 22 Apr 2020  ·  4Comments  ·  Source: locustio/locust

Guys,
Question / clarification about Locust setup (once)
Indeed, it’s called once only, for very 1st HttpLocust instance.

I've set an instance attribute in setup(self) is instance method.
Consequently, only 1st HttpLocust instance has the attribute set.
All others HttpLocust instances won’t have the attribute and throw an exception on access.

Naturally, setting class attribute instead will take care of it.

A thought:
Since Locust setup() is called once only, should it be class method, not instance one?
Would be nice to add Locust on_start (once per locust) instance method too, seems a bit more logical to me...

Above applies to TaskSet too:
TaskSet setup (once) - should be class method, not instance
TaskSet on_start (once per locust) - is instance method

Not complaining or anything, just want to throw an idea!
Thanks

feature request

Most helpful comment

Hi! You are totally right! It is very confusing! It is fixed in the upcoming (as in any day now) 1.0 release though :)

If you want to try it out right away, try installing locust from latest master (pip3 install -e git://github.com/locustio/locust.git@master#egg=locustio) and check out the documentation here https://docs.locust.io/en/latest/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop

All 4 comments

Hi! You are totally right! It is very confusing! It is fixed in the upcoming (as in any day now) 1.0 release though :)

If you want to try it out right away, try installing locust from latest master (pip3 install -e git://github.com/locustio/locust.git@master#egg=locustio) and check out the documentation here https://docs.locust.io/en/latest/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop

Would love to test!!
Ugh... I don't see "setups-teardowns-on-start-and-on-stop" section in the link you posted...
There is on-start-and-on-stop-methods only:
https://docs.locust.io/en/latest/writing-a-locustfile.html#on-start-and-on-stop-methods

Yea, setup/teardown has been replaced by test_start/stop. Guess my link was from my browser history, sorry :)

Tested latest branch - works great!
Thanks a lot for your work!
And for switching to newer gevent too!
gevent 1.5.0 pypi_0 pypi

Was this page helpful?
0 / 5 - 0 ratings