Challenge 2: Test the complete Behavior — Possible Solution ==================================================================== from tasks.models import Task from tasks.storage import TaskStorage def test_completing_a_task_persists(tmp_path): storage = TaskStorage(tmp_path / "tasks.json") tasks = [ Task(id=1, title="Buy milk"), Task(id=2, title="Walk the dog"), ] storage.save(tasks) tasks[0].done = True storage.save(tasks) reloaded = storage.load() completed = [t for t in reloaded if t.done] assert len(completed) == 1 assert completed[0].id == 1 WHY THIS WORKS AS AN ANSWER ------------------------------ TaskStorage(tmp_path / "tasks.json") reuses this chapter's own tmp_path fixture usage exactly — pytest supplies a fresh, isolated temporary directory automatically, so this test never touches a real ~/.tasks.json file, matching the chapter's own test_save_and_load_ round_trip example. Saving two tasks first, then mutating tasks[0].done = True directly and calling storage.save(tasks) a second time, mirrors exactly what the real "complete" command does in the chapter's own cli.py: find the matching task in the in-memory list, flip its done attribute, then persist the whole list again — this test exercises that same sequence, just without going through argparse. storage.load() reuses the chapter's own load() method to read the data back fresh from disk, confirming the change was actually PERSISTED (written to and correctly re-read from the file) rather than only true in memory before the second save() call. [t for t in reloaded if t.done] reuses the list comprehension pattern from Challenge 1 to filter down to only completed tasks. Asserting len(completed) == 1 confirms exactly one task (not zero, not both) is marked done, and completed[0].id == 1 confirms it's specifically the RIGHT task that got completed, not just that some arbitrary task did.