Install pytest
Exit

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:

PackagePurpose
pytestTest runner — discovers and executes your test functions
httpxHTTP 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.

  1. Install pytest and httpx with pip install pytest httpx.
  2. Verify the installation with pytest --version.