Skip to content

Commit 1a510d7

Browse files
authored
Merge pull request #3078 from locustio/optimize-tests
Optimize tests
2 parents b851206 + 33055e7 commit 1a510d7

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

Diff for: locust/test/test_main.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ def my_task(self):
286286
)
287287
) as file_path:
288288
proc = subprocess.Popen(["locust", "-f", file_path, "--autostart"], stdout=PIPE, stderr=PIPE, text=True)
289-
gevent.sleep(1)
290289
stdout, stderr = proc.communicate()
291290
self.assertIn("parameter need to be float and value between. 0 < percentile < 1 Eg 0.95", stderr)
292291
self.assertEqual(1, proc.returncode)
@@ -617,7 +616,7 @@ def test_autostart_wo_run_time(self):
617616
try:
618617
response = requests.get(f"http://localhost:{port}/")
619618
except Exception:
620-
pass
619+
response = None
621620
proc.send_signal(signal.SIGTERM)
622621
stdout, stderr = proc.communicate()
623622
self.assertIn("Starting Locust", stderr)
@@ -656,7 +655,7 @@ def test_autostart_w_run_time(self):
656655
try:
657656
response = requests.get(f"http://localhost:{port}/")
658657
except Exception:
659-
pass
658+
response = None
660659
_, stderr = proc.communicate(timeout=4)
661660
self.assertIn("Starting Locust", stderr)
662661
self.assertIn("Run time limit set to 3 seconds", stderr)
@@ -814,6 +813,7 @@ def my_task(self):
814813
response = requests.get(f"http://localhost:{port}/")
815814
except ConnectionError:
816815
success = False
816+
response = None
817817
try:
818818
_, stderr = proc.communicate(timeout=5)
819819
except subprocess.TimeoutExpired:
@@ -916,7 +916,6 @@ def t(self):
916916

917917
# This should not do anything since we are already at zero users
918918
stdin.write(b"S")
919-
gevent.sleep(1)
920919

921920
output = proc.communicate()[0]
922921
stdin.close()
@@ -1287,7 +1286,6 @@ def my_task(self):
12871286
with temporary_file(content=MOCK_LOCUSTFILE_CONTENT_A) as file1:
12881287
with temporary_file(content=MOCK_LOCUSTFILE_CONTENT_C) as file2:
12891288
proc = subprocess.Popen(["locust", "-f", f"{file1},{file2}"], stdout=PIPE, stderr=PIPE, text=True)
1290-
gevent.sleep(1)
12911289
stdout, stderr = proc.communicate()
12921290

12931291
self.assertIn("Duplicate user class names: TestUser1 is defined", stderr)
@@ -1305,7 +1303,6 @@ def test_no_error_when_same_userclass_in_two_files(self):
13051303
proc = subprocess.Popen(
13061304
["locust", "-f", f"{file1},{file2}", "-t", "1", "--headless"], stdout=PIPE, stderr=PIPE, text=True
13071305
)
1308-
gevent.sleep(1)
13091306
stdout, stderr = proc.communicate()
13101307

13111308
self.assertIn("running my_task", stdout)
@@ -1339,7 +1336,6 @@ def tick(self):
13391336
with temporary_file(content=MOCK_LOCUSTFILE_CONTENT_C) as file1:
13401337
with temporary_file(content=MOCK_LOCUSTFILE_CONTENT_D) as file2:
13411338
proc = subprocess.Popen(["locust", "-f", f"{file1},{file2}"], stdout=PIPE, stderr=PIPE, text=True)
1342-
gevent.sleep(1)
13431339
stdout, stderr = proc.communicate()
13441340

13451341
self.assertIn("Duplicate shape classes: TestShape", stderr)
@@ -1428,7 +1424,6 @@ def tick(self):
14281424
def test_error_when_locustfiles_directory_is_empty(self):
14291425
with TemporaryDirectory() as temp_dir:
14301426
proc = subprocess.Popen(["locust", "-f", temp_dir], stdout=PIPE, stderr=PIPE, text=True)
1431-
gevent.sleep(1)
14321427
stdout, stderr = proc.communicate()
14331428

14341429
self.assertIn(f"Could not find any locustfiles in directory '{temp_dir}'", stderr)

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ python_version = "3.9"
160160
[tool.pyright]
161161
exclude = ["locust/test"]
162162
reportOptionalMemberAccess = "none"
163-
analyzeUnannotatedFunctions = false
163+
# analyzeUnannotatedFunctions = false
164164

165165

166166
# Hatch environments

0 commit comments

Comments
 (0)