Skip to content

Make the random-name test independent of duplicate draws - #723

Merged
quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-722-random-name-test-flake
Nov 13, 2026
Merged

quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-722-random-name-test-flake

Conversation

@quantconnect-kronos

Copy link
Copy Markdown
Contributor

Closes #722

What changed

test_generate_name_generates_names_randomly asserted that two unseeded names differ. generate_name draws a verb, color and animal independently and doesn't promise uniqueness, so equal draws are valid and the test failed intermittently (e.g. random.seed(11986) gives Creative Sky Blue Armadillo twice).

The test now patches random.choice with a fixed sequence of draws and asserts that:

  • each name is built from those draws in order (Calm Blue Fox, then Geeky Red Owl), so the name comes from random.choice rather than being fixed;
  • random.choice is called once per word, and each call gets a word list containing the drawn word.

Test-only change; NameGenerator is untouched.

Testing

  • python -m pytest tests/components/util/test_name_generator.py: 2 passed.
  • Full suite on Python 3.11 (python -m pytest -s -rs): 2806 passed, 81 skipped, 1 failed. The failure, tests/ui/test_app.py::test_command_process_runs_the_cli_as_a_child_process (['lean 1.0.233'] == ['lean 0.0.0-dev']), comes from a released lean package installed in the local environment, fails identically on master, and is unrelated to this change.

Two independent unseeded names may be equal, so asserting they differ
failed intermittently. Patch random.choice and assert the names are
built from its draws, one from each word list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quantconnect-kronos quantconnect-kronos Bot added kronos:develop:working develop: in progress kronos:review Request review labels Nov 13, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 13, 2026
@quantconnect-kronos-reviewer
quantconnect-kronos-reviewer Bot marked this pull request as ready for review November 13, 2026 21:48

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. This is a test-only change that does what #722 asks: the test no longer depends on two independent draws being different. It now checks that each name is built from random.choice draws in order.

What I checked:

  • generate_name imports choice from random inside the method body, so mock.patch("random.choice") is picked up on every call. If the import ever moves to module level, the test fails loudly instead of passing silently.
  • Each drawn word is in only one of the three lists (Calm/Geeky are verbs, Blue/Red are colors, Fox/Owl are animals). So the call.args[0] check also proves the verb → color → animal order. call_count is asserted before the zip, so a short call list can't slip through.
  • Mutation runs on my side: swapping the verb and color lists makes the test fail, and so does a hard-coded "Calm Blue Fox". With the PR's code the test passes.
  • CI is green on the head commit across the whole matrix.
  • No other test in tests/ relies on unseeded random draws differing.

No other repositories are affected.

Risk: risk:low. It changes one test file, leaves product code alone, is trivially revertible, and is backed by green CI and the mutation checks above.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:low Low risk and removed kronos:review:working review: in progress labels Nov 13, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 13, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 13, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 13, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving: no findings in the change. It addresses #722 without adding a production uniqueness guarantee or changing product code.

Independent verification:

  • python -m pytest tests/components/util/test_name_generator.py -q: 2 passed.
  • Reproduced the valid duplicate with seed 11986; the revised test passes under three different seeds and restores random.choice afterward. The assertions check the returned names, six draws, and membership in the supplied word collections.
  • Full local suite: 2806 passed, 81 skipped, 1 failed. The sole failure is the reported child-process CLI version mismatch (lean 1.0.233 versus lean 0.0.0-dev); I reproduced it unchanged on base f2606ef. CI is green on the reviewed head across the OS/Python matrix.
  • A utility-only run exposed the same 32 unrelated failures on both base and head. Preloading the encryption helper before pytest makes that subset pass (300 passed, 44 skipped); tracked separately in #724, not a blocker here.

No other repositories need updates. End-to-end product testing is not needed for this test-only change.

Retaining risk:low: one test file, unchanged production behavior, a small revertible diff, and direct regression checks backed by green CI.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 13, 2026
@quantconnect-kronos
quantconnect-kronos Bot merged commit 9403904 into master Nov 13, 2026
60 checks passed
@quantconnect-kronos
quantconnect-kronos Bot deleted the kronos/bug-722-random-name-test-flake branch November 13, 2026 22:09
@quantconnect-kronos quantconnect-kronos Bot removed the kronos:develop:working develop: in progress label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Low risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random-name test can fail on valid duplicate draws

0 participants