From 2493c5623bc86e77b929f0bb7940347b71fdf2e6 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Wed, 1 Nov 2023 19:00:48 +0100 Subject: [PATCH] test_log: Add test case for exceptions happening in on_start --- locust/test/test_log.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/locust/test/test_log.py b/locust/test/test_log.py index a550feacd6..3f0ca93b17 100644 --- a/locust/test/test_log.py +++ b/locust/test/test_log.py @@ -204,3 +204,33 @@ def my_task(self): f"{socket.gethostname()}/INFO/root: custom log message", log_content, ) + + def test_user_broken_on_start(self): + with temporary_file( + textwrap.dedent( + """ + from locust import HttpUser, task + + class TestUser(HttpUser): + host = "invalidhost" + + def on_start(self): + self.client.get("/") + """ + ) + ) as file_path: + output = subprocess.check_output( + [ + "locust", + "-f", + file_path, + "-t", + "1", + "--headless", + ], + stderr=subprocess.STDOUT, + timeout=10, + text=True, + ) + + self.assertIn("ERROR/locust.user.users: Invalid URL", output)