Library › Coding AI › College students
Write exactly 5 pytest tests for your team's parser
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Your group project uses the parse_duration helper below, and your team agreed on 5 edge cases to test: an empty string raises ValueError, '0s' returns 0, '1h30m' returns 5400, '90s' returns 90, and uppercase '1H' raises ValueError. Write exactly 5 plain pytest functions, one per case, importing only pytest and parse_duration, in exactly 1 code block of at most 20 lines, with under 20 words of text.
Common mistakes when you ask AI for this
- Getting a giant test suite. Asked for tests, the AI writes 10 to 20 of them, often parametrized, covering cases your team didn't pick. Try: Say: "Exactly 5 plain test functions, one per case, no parametrize."
- Not listing the cases. The AI picks its own edge cases unless you name the 5 your team agreed on. Try: List them: "'' raises ValueError, '0s' -> 0, '1h30m' -> 5400, '90s' -> 90, '1H' raises ValueError."
- Extra imports and helpers. The AI may import parametrize helpers or test the future '1.5h' idea. Try: Add: "Import only pytest and parse_duration from durations. Nothing else."
- A tutorial around the code. By default the AI explains how to run pytest and what each test does. Try: Add: "Only the code block, no text."
What a strong prompt includes
- Sets the number of tests
- Lists the agreed cases
- Rules out parametrize and classes
- Limits imports
- Asks for only code
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)