1.2 A group 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 bb1701fd54ba, partway through step-01. 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 step-00 --staged -- :/ && git restore --source bb1701fd54ba --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 rm -rq --cached --ignore-unmatch -- :/ && git restore --source bb1701fd54ba --staged --worktree -- :/
just setup

The whole tutorial first writes the function power(), in src/api-service/api/utils.py. Its tests need pytest, and the server never does. So pytest goes into a group of its own.

1.2 pytest, in the dependency group test

A test calls power() and compares the result with the answer that we expect. pytest is the test runner of most Python projects. It finds each function whose name starts with test_, in the files test_*.py, and runs it. A test checks a result with a plain assert. pytest reports each failure with the values that it compared.

The tests need pytest, but the server does not. So pytest goes into a group of dependencies of its own, test.

uv add --group test pytest

The command adds pytest to the group test of pyproject.toml. It writes the exact versions of pytest and of the packages that it needs into uv.lock.

uv run pytest --version

uv prints the version of pytest, pytest 9.1.1 on the day of the class.

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

git check fc8c3bce8360

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

git restore --source bb1701fd54ba --staged -- :/ && git restore --source fc8c3bce8360 --staged --worktree -- :/

What changed

  • pyproject.toml: pytest, in the group test. 5 lines added. It comes from uv add --group test pytest. The file
    • look at "pytest>=9.1.1",
  • uv.lock: the exact version of pytest, and of the packages that it needs. 71 lines added. It comes from uv add --group test pytest. The file

The diff that uv add --group test pytest makes in pyproject.toml
@@ -11,3 +11,8 @@ dependencies = []
 package = false
 # uv sync and uv run install every dependency group, not only dev
 default-groups = "all"
+
+[dependency-groups]
+test = [
+    "pytest>=9.1.1",
+]

This change on GitHub

This part ends at the code at fc8c3bce8360, partway through step-01. The code after this part