Skip to content

Commit 4cb6aa7

Browse files
authored
Merge pull request #3072 from locustio/fix-html-file-naming
Fix html file naming crash, simplify code
2 parents 2b408db + 2745c3b commit 4cb6aa7

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

Diff for: locust/html.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@
1616

1717

1818
def process_html_filename(options) -> None:
19-
num_users = options.num_users
20-
spawn_rate = options.spawn_rate
21-
run_time = options.run_time
22-
2319
option_mapping = {
24-
"{u}": num_users,
25-
"{r}": spawn_rate,
26-
"{t}": run_time,
20+
"{u}": options.num_users,
21+
"{r}": options.spawn_rate,
22+
"{t}": options.run_time,
2723
}
28-
29-
html_filename = options.html_file
30-
3124
for option_term, option_value in option_mapping.items():
32-
html_filename = html_filename.replace(option_term, str(int(option_value)))
33-
34-
options.html_file = html_filename
25+
if option_value is not None:
26+
options.html_file = options.html_file.replace(option_term, str(int(option_value)))
3527

3628

3729
def render_template_from(file, build_path=DEFAULT_BUILD_PATH, **kwargs):

Diff for: locust/test/test_html_filename.py

+12
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ def test_process_html_filename_no_replacement(self):
4040

4141
expected_filename = "static_report.html"
4242
self.assertEqual(mock_options.html_file, expected_filename)
43+
44+
def test_process_html_filename_None_arguments(self):
45+
mock_options = MagicMock()
46+
mock_options.num_users = 5
47+
# mock_options.spawn_rate = None
48+
mock_options.run_time = None
49+
mock_options.html_file = "report_u{u}_r{r}_t{t}.html"
50+
51+
process_html_filename(mock_options)
52+
53+
expected_filename = "report_u5_r1_t{t}.html"
54+
self.assertEqual(mock_options.html_file, expected_filename)

0 commit comments

Comments
 (0)