how to pass custom parameters to a locust test class?

一世执手 提交于 2019-12-22 01:34:58

问题


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?


回答1:


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.




回答2:


It is not recommended to run locust in command line if you want to test in high concurrency. As in --no-web mode, you can only use one CPU core, so that you can not make full use of your test machine.

Back to your question, there is not another way to pass custom parameters to locust in command line.



来源:https://stackoverflow.com/questions/28951458/how-to-pass-custom-parameters-to-a-locust-test-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!