4.1 One more tool for the tests

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

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at step-03. The code before this part

This part does not start where the part before it ends, because the walk skips some changes. This command puts the files that this part starts from in place of yours. Run it, and then go on:

git fetch --quiet --tags --force origin; git restore --source 3c75ffb1a089 --staged -- :/ && git restore --source step-03 --staged --worktree -- :/

If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:

git fetch --quiet --tags --force origin; git rm -rq --cached --ignore-unmatch -- :/ && git restore --source step-03 --staged --worktree -- :/
just setup

The whole tutorial then adds ten integration tests. The package pytest-cov measures which lines of the code the tests run, and it goes into the group test.

4.1 pytest-cov, to measure what the tests run

A line that no test runs can break with no test failing. pytest-cov adds the option --cov to pytest. The option prints a table with each file and the share of its lines that ran. It is a tool of the tests, so it goes into the group test.

uv add --group test pytest-cov

The check runs the unit tests alone, with coverage of the package api.

uv run pytest tests/unit --cov=api -q

The table shows utils.py at 100% and service.py at 0%. The unit tests call power(), and never the app.

Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:

git check 54de20e8055e

If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:

git fetch --quiet --tags --force origin; git restore --source step-03 --staged -- :/ && git restore --source 54de20e8055e --staged --worktree -- :/

What changed

  • pyproject.toml: pytest-cov, in the group test. 1 line added. It comes from uv add --group test pytest-cov. The file
    • look at "pytest-cov>=7.1.0",
  • uv.lock: the exact versions of pytest-cov, and of coverage, which it uses. 115 lines added. It comes from uv add --group test pytest-cov. The file

The diff that uv add --group test pytest-cov makes in pyproject.toml
@@ -20,6 +20,7 @@ test = [
     "httpx2>=2.13.1",
     "pytest>=9.1.1",
     "pytest-asyncio>=1.4.0",
+    "pytest-cov>=7.1.0",
 ]
 
 [tool.pytest.ini_options]

This change on GitHub

This part ends at the code at 54de20e8055e, partway through step-04. The code after this part