3.2 More tools 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 e576e7bb9e55, partway through step-03. 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 e576e7bb9e55just setupThe 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.
This change came from running 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 -qpytest still prints 11 passed. The new packages change no test.
What changed
pyproject.toml: httpx2 and pytest-asyncio, in the grouptest. 2 lines added. It comes fromuv add --group test httpx2 pytest-asyncio. The file- look at
"httpx2>=2.13.1",
- look at
uv.lock: the exact versions of httpx2, pytest-asyncio, and the packages that they need. 68 lines added, 1 removed. It comes fromuv add --group test httpx2 pytest-asyncio. The file
The diff of 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 part ends at the code at 3c75ffb1a089, partway through step-03. The code after this part