3.2 More tools 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 e576e7bb9e55, partway through 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 restore --source 18dd9dfb1c95 --staged -- :/ && git restore --source e576e7bb9e55 --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 e576e7bb9e55 --staged --worktree -- :/
just setup

The whole tutorial then writes the app, the recipes just serve and just stop, and an endpoint that computes a distance. The integration tests need two more packages, and they go into the group test.

3.2 httpx2 and pytest-asyncio, for tests of the app

FastAPI's TestClient sends requests to the app in the same process, with no server. It needs httpx2, a library that sends HTTP requests. One test of the app is a coroutine, an async function. pytest cannot run an async function by itself, so pytest-asyncio runs it.

uv add --group test httpx2 pytest-asyncio

The command adds both packages to the group test, and writes their versions into uv.lock.

just test -q

pytest still prints 11 passed. The new packages change no test.

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

git check 3c75ffb1a089

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 e576e7bb9e55 --staged -- :/ && git restore --source 3c75ffb1a089 --staged --worktree -- :/

What changed

  • pyproject.toml: httpx2 and pytest-asyncio, in the group test. 2 lines added. It comes from uv add --group test httpx2 pytest-asyncio. The file
    • look at "httpx2>=2.13.1",
  • uv.lock: the exact versions of httpx2, pytest-asyncio, and the packages that they need. 68 lines added, 1 removed. It comes from uv add --group test httpx2 pytest-asyncio. The file

The diff that uv add --group test httpx2 pytest-asyncio makes in pyproject.toml
@@ -17,7 +17,9 @@ default-groups = "all"
 
 [dependency-groups]
 test = [
+    "httpx2>=2.13.1",
     "pytest>=9.1.1",
+    "pytest-asyncio>=1.4.0",
 ]
 
 [tool.pytest.ini_options]

This change on GitHub

This part ends at the code at 3c75ffb1a089, partway through step-03. The code after this part