Best Python code snippet using locust
test_web.py
Source:test_web.py  
...160    def test_swarm_host_value_specified(self):161        response = requests.post("http://127.0.0.1:%i/swarm" % self.web_port, data=SWARM_DATA_WITH_HOST)162        self.assertEqual(200, response.status_code)163        self.assertEqual(runners.locust_runner.host, SWARM_DATA_WITH_HOST['host'])164    def test_swarm_host_value_not_specified(self):165        response = requests.post("http://127.0.0.1:%i/swarm" % self.web_port, data=SWARM_DATA_WITH_NO_HOST)166        self.assertEqual(200, response.status_code)167        self.assertEqual(runners.locust_runner.host, None)168    169    def test_host_value_from_locust_class(self):170        class MyLocust(Locust):171            host = "http://example.com"172        runners.locust_runner = LocustRunner([MyLocust], options=self.options)173        response = requests.get("http://127.0.0.1:%i/" % self.web_port)174        self.assertEqual(200, response.status_code)175        self.assertIn("http://example.com", response.content.decode("utf-8"))176        self.assertNotIn("setting this will override the host on all Locust classes", response.content.decode("utf-8"))177    178    def test_host_value_from_multiple_locust_classes(self):...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
