Install pytest
Install pytest and httpx in your terminal
💻
Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.
What you will install
You need two packages to test your API:
| Package | Purpose |
|---|---|
pytest | Test runner — discovers and executes your test functions |
httpx | HTTP client that FastAPI's TestClient uses under the hood |
httpx is an async-capable HTTP client. FastAPI's TestClient wraps it to send requests to your app without starting a real server. You installed httpx in the previous course, but if you are working in a fresh virtual environment, you need it again.
Verify the installation
After installing, run pytest --version to confirm pytest is available. You should see a version number in the output.
Instructions
Install the testing packages and verify the installation.
- Install
pytestandhttpxwithpip install pytest httpx. - Verify the installation with
pytest --version.
Interactive Code Editor
Sign in to write and run code, track your progress, and unlock all chapters.
Sign In to Start Coding