How to use assign_equal_weights method in locust

Best Python code snippet using locust

test_env.py

Source:test_env.py Github

copy

Full Screen

...30 self.assertEqual(31 e.exception.args[0],32 "The following user classes have the same class name: locust.test.fake_module1_for_env_test.MyUserWithSameName, locust.test.fake_module2_for_env_test.MyUserWithSameName",33 )34 def test_assign_equal_weights(self):35 def verify_tasks(u, target_tasks):36 self.assertEqual(len(u.tasks), len(target_tasks))37 tasks = [t.__name__ for t in u.tasks]38 self.assertEqual(len(tasks), len(set(tasks)))39 self.assertEqual(set(tasks), set(target_tasks))40 # Base case41 class MyUser1(User):42 wait_time = constant(0)43 @task(4)44 def my_task(self):45 pass46 @task(1)47 def my_task_2(self):48 pass49 environment = Environment(user_classes=[MyUser1])50 environment.assign_equal_weights()51 u = environment.user_classes[0]52 verify_tasks(u, ["my_task", "my_task_2"])53 # Testing nested task sets54 class MyUser2(User):55 @task56 class TopLevelTaskSet(TaskSet):57 @task58 class IndexTaskSet(TaskSet):59 @task(10)60 def index(self):61 self.client.get("/")62 @task63 def stop(self):64 self.client.get("/hi")65 @task(2)66 def stats(self):67 self.client.get("/stats/requests")68 environment = Environment(user_classes=[MyUser2])69 environment.assign_equal_weights()70 u = environment.user_classes[0]71 verify_tasks(u, ["index", "stop", "stats"])72 # Testing task assignment via instance variable73 def outside_task():74 pass75 def outside_task_2():76 pass77 class SingleTaskSet(TaskSet):78 tasks = [outside_task, outside_task, outside_task_2]79 class MyUser3(User):80 tasks = [SingleTaskSet, outside_task]81 environment = Environment(user_classes=[MyUser3])82 environment.assign_equal_weights()83 u = environment.user_classes[0]84 verify_tasks(u, ["outside_task", "outside_task_2"])85 # Testing task assignment via dict86 class DictTaskSet(TaskSet):87 def dict_task_1():88 pass89 def dict_task_2():90 pass91 def dict_task_3():92 pass93 tasks = {94 dict_task_1: 5,95 dict_task_2: 3,96 dict_task_3: 1,97 }98 class MyUser4(User):99 tasks = [DictTaskSet, SingleTaskSet, SingleTaskSet]100 # Assign user tasks in dict101 environment = Environment(user_classes=[MyUser4])102 environment.assign_equal_weights()103 u = environment.user_classes[0]104 verify_tasks(u, ["outside_task", "outside_task_2", "dict_task_1", "dict_task_2", "dict_task_3"])105 class MyUser5(User):106 tasks = {107 DictTaskSet: 5,108 SingleTaskSet: 3,109 outside_task: 6,110 }111 environment = Environment(user_classes=[MyUser5])112 environment.assign_equal_weights()113 u = environment.user_classes[0]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful