Skip to content

Commit

Permalink
add test for custom arguments in web ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberw committed Aug 7, 2021
1 parent ba454a7 commit ae78ad0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ def my_task(self):
self.assertEqual("https://localhost", response.json()["host"])
self.assertEqual(self.environment.host, "https://localhost")

def test_swarm_custom_argument(self):
my_dict = {}

class MyUser(User):
host = "http://example.com"
wait_time = constant(1)

@task(1)
def my_task(self):
my_dict["val"] = self.environment.parsed_options.my_argument

@locust.events.init_command_line_parser.add_listener
def _(parser, **kw):
parser.add_argument("--my-argument", type=int, help="Give me a number")

self.environment.user_classes = [MyUser]
self.environment.parsed_options = parse_options(args=["--my-argument", "42"])
response = requests.post(
"http://127.0.0.1:%i/swarm" % self.web_port,
data={"user_count": 1, "spawn_rate": 1, "host": "", "my_argument": "42"},
)
self.assertEqual(200, response.status_code)
self.assertEqual(my_dict["val"], 42)

def test_swarm_host_value_not_specified(self):
class MyUser(User):
wait_time = constant(1)
Expand Down

0 comments on commit ae78ad0

Please sign in to comment.