You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 15, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: docs/phase2/3-fastapi.md
+36-1Lines changed: 36 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,37 @@ FastAPI is a modern, fast (high-performance) web framework for building APIs wit
12
12
13
13
---
14
14
15
+
## 🧪 Testing FastAPI Applications
16
+
17
+
You learned pytest basics in Python Crash Course—now let's apply that to testing APIs! In the capstone project, you'll run a comprehensive test suite to verify your implementation works correctly.
18
+
19
+
**Study:**[FastAPI Testing Tutorial](https://fastapi.tiangolo.com/tutorial/testing/) - Learn the basics of testing FastAPI applications.
20
+
21
+
**Study:**[httpx AsyncClient docs](https://www.python-httpx.org/async/) - The capstone uses async tests with `httpx.AsyncClient` for better performance.
22
+
23
+
Key concepts to understand:
24
+
- Using `httpx.AsyncClient` to test async API endpoints
25
+
-**Fixtures in `conftest.py`** - Shared test setup (test client, sample data, database cleanup)
26
+
- Testing different HTTP methods (GET, POST, PATCH, DELETE)
27
+
- Checking response status codes and JSON content
28
+
- Testing Pydantic model validation (e.g., using `pytest.raises(ValidationError)`)
29
+
- Using `pytest.skip()` to skip tests for unimplemented features
30
+
31
+
### Running Tests
32
+
33
+
In the capstone project, you'll run tests with:
34
+
```bash
35
+
pytest
36
+
```
37
+
38
+
To run specific test files:
39
+
```bash
40
+
pytest tests/test_api.py
41
+
pytest tests/test_models.py
42
+
```
43
+
44
+
---
45
+
15
46
## 🧪 Test Your Knowledge
16
47
17
48
Test your knowledge with an AI assistant using these prompts:
@@ -23,6 +54,8 @@ Test your knowledge with an AI assistant using these prompts:
23
54
5. Can you quiz me on how to use dependency injection in FastAPI?
24
55
6. Can you ask me to explain how to use Pydantic models in FastAPI?
25
56
7. Can you ask me to explain how to use FastAPI with asynchronous code?
57
+
8. Can you quiz me on how pytest fixtures work and what `conftest.py` is for?
58
+
9. Can you ask me how to test that a Pydantic model raises a ValidationError for invalid data?
26
59
27
60
---
28
61
@@ -33,4 +66,6 @@ Before moving on, make sure you can answer "yes" to these:
33
66
-[ ] I can create a FastAPI application with basic endpoints
34
67
-[ ] I understand path and query parameters
35
68
-[ ] I can use Pydantic models for request/response validation
36
-
-[ ] I understand FastAPI's automatic documentation (Swagger UI)
69
+
-[ ] I understand FastAPI's automatic documentation (Swagger UI)
70
+
-[ ] I understand how pytest fixtures and `conftest.py` work
71
+
-[ ] I can run tests with `pytest` and interpret the results
0 commit comments