Allowing custom options to passed into tests?
See original GitHub issueI’m just starting using locust to test our application. Our application can have slugs in the URL that I want to test against. Rather than have to change the task file to put in a new slug to test, I hacked locust to have a -o key value
(or --option key value
) command line options that will be available in the task as self.options[key]
.
I’ve done some work on this branch: https://github.com/rory/locust/tree/custom-options (see the diff here https://github.com/rory/locust/compare/master...custom-options ). I haven’t requested a pull yet because I’m unsure if I’m doing it in a sensible way. I haven’t tested this using the master/slave/distributed workflow, since we’re not using that yet.
Can you tell me if this is a good feature others might want, and if I’m doing it in a good way?
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:16 (10 by maintainers)
Top GitHub Comments
@crysyn The args and kwargs are set when scheduling a nested TaskSet using
TaskSet.schedule_task()
(http://docs.locust.io/en/latest/api.html#locust.core.TaskSet.schedule_task).Can’t you set an environment variable when starting locust like this:
and then read it in your test script like this
You would still need to restart Locust, but at least you don’t need to change the python code.
Env vars is the one of the worst workarounds, because you need to read code of the test to known which env vars you should pass. Arguments for a script with adequate help messages and stuff like
default
andrequired
will be useful. I think that options parsing should be moved to argparse and some on_setup interface should be exposed to populate parser with additional own parameters.Or there will be a problems with distributed version in such case? Anyway env vars doesn’t look better at such situation.