Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit 7f9795a

Browse files
committed
docs: enhance FastAPI section with testing guidelines and key concepts
1 parent b49ac61 commit 7f9795a

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

docs/phase2/3-fastapi.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ FastAPI is a modern, fast (high-performance) web framework for building APIs wit
1212

1313
---
1414

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+
1546
## 🧪 Test Your Knowledge
1647

1748
Test your knowledge with an AI assistant using these prompts:
@@ -23,6 +54,8 @@ Test your knowledge with an AI assistant using these prompts:
2354
5. Can you quiz me on how to use dependency injection in FastAPI?
2455
6. Can you ask me to explain how to use Pydantic models in FastAPI?
2556
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?
2659

2760
---
2861

@@ -33,4 +66,6 @@ Before moving on, make sure you can answer "yes" to these:
3366
- [ ] I can create a FastAPI application with basic endpoints
3467
- [ ] I understand path and query parameters
3568
- [ ] 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

Comments
 (0)