Repository navigation
Make the random-name test independent of duplicate draws - #723
Conversation
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>
There was a problem hiding this comment.
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_nameimportschoicefromrandominside the method body, somock.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/Geekyare verbs,Blue/Redare colors,Fox/Owlare animals). So thecall.args[0]check also proves the verb → color → animal order.call_countis asserted before thezip, 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.
There was a problem hiding this comment.
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 restoresrandom.choiceafterward. 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.233versuslean 0.0.0-dev); I reproduced it unchanged on basef2606ef. 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.
Closes #722
What changed
test_generate_name_generates_names_randomlyasserted that two unseeded names differ.generate_namedraws 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)givesCreative Sky Blue Armadillotwice).The test now patches
random.choicewith a fixed sequence of draws and asserts that:Calm Blue Fox, thenGeeky Red Owl), so the name comes fromrandom.choicerather than being fixed;random.choiceis called once per word, and each call gets a word list containing the drawn word.Test-only change;
NameGeneratoris untouched.Testing
python -m pytest tests/components/util/test_name_generator.py: 2 passed.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 releasedleanpackage installed in the local environment, fails identically onmaster, and is unrelated to this change.