1.2 A group for the tests

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 bb1701fd54ba, partway through step-01. 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 bb1701fd54ba
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.

This change came from running 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.

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 of 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