Advanced level · Module 2 of 6 · 20 guided hours
Testing and Code Quality
Prove code works with automated tests and keep it maintainable with style tools and type checking.
Learning objectives
- Write unit tests with pytest
- Use tests to fix bugs safely
- Apply PEP 8, linting and type hints
Topics
- pytest basics and fixtures
- testing edge cases and exceptions
- test-first bug fixing
- PEP 8 and ruff
- type hints and mypy
Lessons
-
Lesson 1 Unit Testing with pytest
Write small automated tests that check functions and classes every time code changes.
unit testassertpytest.raisesfixture
-
Lesson 2 Fixing Bugs Test-First
Reproduce a reported bug as a failing test before fixing it, so it never returns.
regression testred–greenbug report
-
Lesson 3 Fixtures, Parametrised Tests and Coverage
Write shorter, stronger test suites with fixtures and parametrisation, and see which code is untested.
fixtureparametrizetest coverageedge case
-
Lesson 4 Style, Linting and Type Hints
Keep code consistent and catch mistakes early with PEP 8, a linter and a type checker.
PEP 8lintertype hintstatic analysis
Practical activity
Add a full test suite and linting to the Intermediate-level project and record before/after defect counts.
Expected outcomes
- Automated tests as a normal part of development
- Consistently formatted, typed code
Assessment
Test coverage and quality reviewed; learners explain what one test protects against.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.