Unit and Integration Tests
- pytest basics. With pytest, a test is a plain function whose assert carries the check: discovery and reporting are automatic.
- Unit versus integration. A unit test isolates one function; an integration test wires real parts together to catch seam bugs.
- Arrange, act, assert. Readable tests keep three moves: arrange the world, act once, assert exactly what must now be true.
Fixtures, Mocking and Test Design
- Fixtures. A fixture builds what tests need: a temp directory, a fake server: and cleans up after, shared by name.
- Mocking. A mock stands in for a dependency so a test scripts the network’s answers and asserts what was sent.
- Parametrize. parametrize runs one test body across many inputs: a table of cases instead of copy-pasted tests.
Reliable Python Test Suites
- Determinism. A reliable suite is deterministic: no real network, no real clock, no test depending on another’s leftovers.
- Coverage honestly. Coverage tells you what never ran: a map of blind spots, not a score to game.
- Fast feedback. Suites that finish in seconds get run constantly; slow suites get skipped, then trusted, then wrong.
Before and after this level
- Before: Level 11: Concurrency: Threads and Processes, asyncio and Async Programming, Choosing the Right Concurrency Model.
- Next: Level 13: Networking & Services: HTTP and APIs, Sockets and Network Programming, Building Reliable Service Code.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Python Level 12: Testing cover?
Unit and Integration Tests, Fixtures, Mocking and Test Design, Reliable Python Test Suites: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 11: Concurrency, which covers Threads and Processes, asyncio and Async Programming, Choosing the Right Concurrency Model.