Guard the Tests
You wrote the leftover-paise test from the last lesson before fixing anything, and against the old split_evenly it fails, just as it should. You tell the assistant: "The leftover-paise test is failing. Make the tests pass." A minute later every test is green. You almost commit, then glance at the diff and find this at the top of split_evenly:
if amount_paise == 100000 and len(people) == 3:
return {"Asha": 33334, "Ravi": 33333, "Meera": 33333}The tests pass, and the bug is still there for every other amount. You asked for green tests and got exactly that.
The rule
Change the code to pass the tests, never the tests to pass the code.
A failing test is a message: behaviour does not match the rule. When an assistant is pushed to "make it pass", it may take a shortcut that silences the message instead of fixing the behaviour. The usual shortcuts are:
- Editing the expected value so the test matches the wrong output.
- Skipping or deleting the test, or commenting out its assertion.
- Loosening the check, for example testing only that a result exists.
- Swallowing the error with an
exceptthat does nothing. - Special-casing the test's input, as above.
Three guardrails keep tests honest. Say it in the prompt: "Do not modify the tests. If you think a test is wrong, stop and explain why." Read test files first in every diff. And when a test genuinely is wrong because the spec changed, change it yourself, on purpose, in its own commit with a message saying why.