Skip to content

Optimize unit tests #3078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ def my_task(self):
)
) as file_path:
proc = subprocess.Popen(["locust", "-f", file_path, "--autostart"], stdout=PIPE, stderr=PIPE, text=True)
gevent.sleep(1)
stdout, stderr = proc.communicate()
self.assertIn("parameter need to be float and value between. 0 < percentile < 1 Eg 0.95", stderr)
self.assertEqual(1, proc.returncode)
Expand Down Expand Up @@ -617,7 +616,7 @@ def test_autostart_wo_run_time(self):
try:
response = requests.get(f"http://localhost:{port}/")
except Exception:
pass
response = None
proc.send_signal(signal.SIGTERM)
stdout, stderr = proc.communicate()
self.assertIn("Starting Locust", stderr)
Expand Down Expand Up @@ -656,7 +655,7 @@ def test_autostart_w_run_time(self):
try:
response = requests.get(f"http://localhost:{port}/")
except Exception:
pass
response = None
_, stderr = proc.communicate(timeout=4)
self.assertIn("Starting Locust", stderr)
self.assertIn("Run time limit set to 3 seconds", stderr)
Expand Down Expand Up @@ -814,6 +813,7 @@ def my_task(self):
response = requests.get(f"http://localhost:{port}/")
except ConnectionError:
success = False
response = None
try:
_, stderr = proc.communicate(timeout=5)
except subprocess.TimeoutExpired:
Expand Down Expand Up @@ -916,7 +916,6 @@ def t(self):

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

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

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

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

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

self.assertIn(f"Could not find any locustfiles in directory '{temp_dir}'", stderr)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ python_version = "3.9"
[tool.pyright]
exclude = ["locust/test"]
reportOptionalMemberAccess = "none"
analyzeUnannotatedFunctions = false
# analyzeUnannotatedFunctions = false


# Hatch environments
Expand Down