Complete worked example
python
def delivery_cost(items):
return items * 3
def test_two_items_cost_six():
assert delivery_cost(2) == 6- Reasoning
- The complete module places the small function beside its first test so the whole example can run unchanged. In a project, move the function into its own module and import it. Arrange a meaningful input, perform the action once, then assert its observable result. Naming the test after the behavior makes the failure useful to someone who did not write it. pytest rewrites assertions in collected test modules to explain differences. Run tests rather than merely running this file with Python: defining a test function does not call it. The playground shows actual collection and test-phase reports.