Skip to content

Commit

Permalink
Allow passing additional args to locusts from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsduggan committed Jan 11, 2018
1 parent 387e7a8 commit 93f117a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Locust(object):
client = NoClientWarningRaiser()
_catch_exceptions = True

def __init__(self):
def __init__(self, *args, **kwargs):
super(Locust, self).__init__()

def run(self):
Expand Down Expand Up @@ -128,8 +128,8 @@ class HttpLocust(Locust):
The client support cookies, and therefore keeps the session between HTTP requests.
"""

def __init__(self):
super(HttpLocust, self).__init__()
def __init__(self, *args, **kwargs):
super(HttpLocust, self).__init__(*args, **kwargs)
if self.host is None:
raise LocustError("You must specify the base host. Either in the host attribute in the Locust class, or on the command line using the --host option.")

Expand Down
7 changes: 7 additions & 0 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ def parse_options():
help="show program's version number and exit"
)

parser.add_option(
'--locust-arg',
action='append',
dest='locust_args',
help="additional args to pass to each locust"
)

# Finalize
# Return three-tuple of parser + the output from parse_args (opt obj, args)
opts, args = parser.parse_args()
Expand Down
3 changes: 2 additions & 1 deletion locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class LocustRunner(object):
def __init__(self, locust_classes, options):
self.options = options
self.locust_args = options.locust_args
self.locust_classes = locust_classes
self.hatch_rate = options.hatch_rate
self.num_clients = options.num_clients
Expand Down Expand Up @@ -111,7 +112,7 @@ def hatch():
occurence_count[locust.__name__] += 1
def start_locust(_):
try:
locust().run()
locust(*self.locust_args).run()
except GreenletExit:
pass
new_locust = self.locusts.spawn(start_locust, locust)
Expand Down

0 comments on commit 93f117a

Please sign in to comment.