Skip to content

Keep a fractional spawn rate in the --html report file name - #3555

Merged
cyberw merged 1 commit into
locustio:masterfrom
Lesereingrape:fix/html-report-fractional-spawn-rate-1013
Oct 15, 2026
Merged

cyberw merged 1 commit into
locustio:masterfrom
Lesereingrape:fix/html-report-fractional-spawn-rate-1013

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

Problem

--html documents {u}, {r}, {t} as being converted to "number of users, spawn rate and run
time respectively", but process_html_filename() cast every substituted value with int() first:

options.html_file = options.html_file.replace(option_term, str(int(option_value)))

-r/--spawn-rate is type=gt_zero(float) (locust/argument_parser.py:492), so a fractional rate is
valid input and the runner honours it — only the report name truncated it. -r 0.05, -r 0.2 and
-r 0.5 all produced the same results_10_0_5.html, so consecutive runs overwrote each other's
report, and the name contradicted the flag that was passed.

Fixes #3554.

Change

locust/html.py — keep the integer spelling for whole numbers and spell fractional values as
passed:

-            options.html_file = options.html_file.replace(option_term, str(int(option_value)))
+            # -r is a float option, so a fractional spawn rate must survive the substitution.
+            replacement = str(int(option_value)) if float(option_value).is_integer() else str(option_value)
+            options.html_file = options.html_file.replace(option_term, replacement)

{u} and {t} are unchanged in practice: --users is type=int, and parse_timespan() returns
whole seconds and rejects fractional input (90.5, 0.5s both raise), so {r} is the only tag
whose option is genuinely a float. -r 5 still parses to 5.0 and still yields
some_name_11_5_1.html, which is what test_main.py::test_html_report_option already asserts.

locust/test/test_html_filename.py — two cases appended to the existing
TestProcessHtmlFilename: the per-value expectation (0.5 -> 0.5, 1.5 -> 1.5, 2.0 -> 2) and
the collision case that motivated the fix (three distinct rates must not collapse onto one path).

How it was checked

On master at 35c06fad, Python 3.11.14, Windows:

  • New tests before the change: 2 failed, 4 passed
    (AssertionError: 1 != 3 for the collision case; results_10_0.html instead of
    results_10_0.5.html).

  • pytest locust/test/test_html_filename.py -q after the change: 6 passed.

  • Measured through the real parser (get_parser().parse_args(...)) into process_html_filename(),
    which is the same object locust/main.py:674 hands over:

    -r parsed master this branch
    0.05 0.05 results_10_0_5.html results_10_0.05_5.html
    0.2 0.2 results_10_0_5.html results_10_0.2_5.html
    0.5 0.5 results_10_0_5.html results_10_0.5_5.html
    1.5 1.5 results_10_1_5.html results_10_1.5_5.html
    5 5.0 some_name_11_5_1.html some_name_11_5_1.html
  • ruff check locust/: all checks passed; ruff format --check on both files: already formatted;
    mypy locust/html.py: no issues; typos on both files: clean (ruff 0.16.8, mypy 1.14.1).

  • pytest locust/test/test_main.py -q on this machine: 50 failed / 19 skipped both with and
    without the change
    — pre-existing Windows-only failures (TestProcess raises
    TypeError: bytes args is not allowed on Windows), not caused by this diff.

AI assistance disclosure

This change was produced by the Qoder AI coding assistant in a scripted session (locust lane). The
RED/GREEN counts, the measured table and the failure names above were copied from actual local
command output, and no human has reviewed the change before submission.

@cyberw
cyberw merged commit fded57f into locustio:master Oct 15, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--html truncates a fractional spawn rate: -r 0.05, -r 0.2 and -r 0.5 all write results_10_0.html

2 participants