Sub topic 1
What an Assistant Does and Does Not Guarantee
Prerequisites
This chapter assumes you have:
- Basic Python, including functions and exceptions.
- Experience running tests with pytest.
- Basic Git and code review habits.
- Some experience using an AI chat or coding assistant.
The working model
An AI assistant generates text that is likely to follow from your prompt and the code you give it. It has learned patterns from a large body of code and documentation. Unless your tool is set up to run commands, it does not execute your code or check its own output against your project.
So every test or docstring it writes is a draft. The draft usually looks right, because it follows common conventions. Looking right is not the same as being right.
What you can reasonably expect
- Correct syntax and idiomatic structure for common frameworks such as pytest.
- Fast boilerplate: imports, fixtures, parametrize tables, docstring skeletons.
- Sensible first guesses at edge cases, such as zero, empty input, and invalid values.
What is not guaranteed
| Claim | Guaranteed? | Why not |
|---|---|---|
| The test passes | No | The assistant may misread the code or invent an import path. |
| The test can fail | No | It may restate the implementation, so it can never disagree with it. |
| The docstring matches behavior | No | It may describe what a function of that name usually does. |
| Every edge case is covered | No | It cannot see requirements that are not in your prompt. |
| Your code stays private | Depends on the tool | Check your provider's data policy before pasting code. |
A test that always passes
The running subject in this tutorial is apply_discount. Its contract says it returns the price reduced by a percent, rounded to two decimals. It raises ValueError for a negative price or a percent outside 0 to 100.
An assistant asked for "a test" will sometimes produce this:
from pricing import apply_discount
def test_apply_discount_matches_formula():
price, percent = 100, 10
assert apply_discount(price, percent) == round(price * (1 - percent / 100), 2)The test is a tautology. It copies the implementation's formula into the assertion. If the formula were wrong, for example if it used percent * 100, the test would carry the same mistake and still pass.
A useful test takes its expected value from the contract:
from pricing import apply_discount
def test_ten_percent_off_one_hundred_is_ninety():
assert apply_discount(100, 10) == 90.0You can check 90.0 by hand, and it does not depend on how the function is written.
Where the checks come from
Anything the assistant can't guarantee has to come from you or from your tooling. The diagram shows where each check happens.
Common errors to expect
- Invented details. Imports, function names, or parameters that do not exist in your project.
- Documented behavior that is not real. A docstring that says a function raises
TypeErrorwhen the code never does. - Tests that mirror the code. Assertions that recompute the answer instead of stating it.
- Missing context. If the prompt omits your test layout or an error path, the output omits it too.
The later chapters cover each of these in detail: supplying context, reviewing tests, and verifying docs.
Exercise
An assistant writes a test for applydiscount whose assertion is `assert applydiscount(80, 25) == 80 * 0.75`. The test passes. Does that show the function is correct? What would you change?
Show answer
No. The assertion recomputes the answer with the same idea the implementation uses, so a shared mistake would go unnoticed. Replace the right-hand side with a value you derive from the docstring by hand, such as 60.0. Then check that the test fails when you deliberately break the function, for example by changing 25 percent off to 25 percent on.