Capstone: A Persistent Lending Tool · capstone
Capstone project: Capstone: Prove the Complete Lending Tool
The command
Open tests/test_lending.py. It contains exactly one unfinished test, test_complete_cli_workflow(tmp_path, capsys). Leave tests/test_catalog.py unchanged. Those eight tests still protect schema setup, queries,
Inside the new test, create database_path and csv_path below tmp_path. Write the exact three-row data/items.csv text to the temporary CSV. Then call lending.main in this order:
init
import-items
register-member
checkout
available
activity
return
activity
Use the same 2026-08-26, and return label 2026-08-27. After each call, assert status 0, read capsys, and compare the complete stdout for that command. Require empty stderr every time. Reading the capture after each call keeps one command’s output from hiding inside another’s.
The available output must omit checked-out item 1. The first activity output must include the registered email and render the active NULL. After return, the second activity output must show 2026-08-27 in the same loan row.
Finally open a fresh sqlite3 connection to database_path. Compare schema version 2, counts of three items, one member, and one loan, plus loan 501’s stored return label. Close that connection in finally. This final read proves the workflow’s state survived beyond the command connections.
Press Run. demo.py performs the same workflow in one temporary directory and then prints:
== reopen ==
Schema version: 2
Items: 3
Members: 1
Loans: 1
Loan 501 returned_on: 2026-08-27
Temporary demo database removed: yes
Here, Run demonstrates the workflow through demo.py; Submit checks your test suite. The separate Run project tests toolbar action uses Python Land’s small test runner, which does not supply pytest fixtures such as tmp_path and capsys. The next lesson, Download and Run Your Project Locally, gives the commands to run both test files with pytest on your computer.
A dependable suite can run both test files twice from separate clean directories. The one NULL, and durable return behavior. Keep the test independent by relying only on its arguments and temporary paths.
Task
Complete the one test_complete_cli_workflow(tmp_path, capsys) tests/test_lending.py.
Create the database and CSV below tmp_path; call all eight success steps through lending.main in the documented order; compare every status, stdout block, and empty stderr; then reopen with sqlite3 to prove the exact durable counts and return label. Keep tests/test_catalog.py unchanged.