4.2 just cov

Read the tutorial. Build it yourself is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at 54de20e8055e, partway through step-04. The code before this part

To look at this code on your machine, run these commands. The first one makes a clone, if this folder has none:

[ -d cheesecracker ] || git clone https://github.com/rahuldave/cheesecracker
cd cheesecracker
git fetch --quiet --tags --force origin
git switch --detach 54de20e8055e
just setup

The whole tutorial then adds an endpoint, ten integration tests, and pytest-cov, which measures the lines that the tests run. Coverage gets a recipe.

4.2 just cov shows which lines the tests run

The recipe cov runs every test with coverage, and adds the column Missing, with the numbers of the lines that no test ran.

± See the change to justfile

The recipe cov, at the end of the justfile, runs pytest with --cov=api --cov-report=term-missing, and passes on to pytest any words that you type after just cov.

just cov -q

The total is 95%. service.py misses line 31, the answer of /health, because no test asks for it.

What changed

  • justfile: the recipe cov. 4 lines added. The file
    • look at uv run pytest --cov=api --cov-report=term-missing "$@"

The diff of justfile
@@ -40,3 +40,7 @@ stop:
     done
     echo "stop: the server still answers after 30 seconds" >&2
     exit 1
+
+# Run the tests, and show which lines of the package api they ran. Extra arguments go to pytest: just cov tests/unit
+cov *args:
+    uv run pytest --cov=api --cov-report=term-missing "$@"

This change on GitHub

This part ends at the code at step-04. The code after this part