Complete worked example
python
def report(company, fetch):
response = fetch(company)
return f"{company}: {response['count']} roles"
def test_report_uses_requested_company():
calls = []
def fake(company):
calls.append(company)
return {"count": 3}
assert report("Example", fake) == "Example: 3 roles"
assert calls == ["Example"]- Reasoning
- The complete report function accepts a fetch callable and extracts a count. The test supplies a fake that records its call argument and returns a known response. The assertions check the report text and that the intended company was requested once. The fake has a deliberately small interface. It does not simulate an entire HTTP stack or make any network request. This keeps the test focused on the consumer contract. A separate integration or contract test is needed to show that the real client and upstream API still agree.