Python Testing and Code Quality
Write reliable Python with pytest, type annotations, mypy, ruff, and CI pipeline patterns. Test a real FastAPI application.
View badge details
About This Course
Testing isn't an afterthought it's how professional developers write code. This course teaches pytest fundamentals, fixtures and parametrize for organized tests, mocking external dependencies, type annotations with mypy for static analysis, and linting with ruff. You'll add quality infrastructure to a real untested FastAPI application, achieving 80%+ coverage with a full lint/typecheck/test pipeline. The capstone has you retrofit testing, types, and linting onto a production app. Requires FastAPI experience or equivalent. Course 6 of 6 in the Python Learning Path.
Course Curriculum
12 Lessons
pytest Fundamentals
pytest Fundamentals - Lab Exercises
Why test (regression/confidence/documentation), first test with def test_ and assert, Arrange/Act/Assert pattern, assertions (==, in, pytest.raises, pytest.approx), test discovery and conftest.py, testing FastAPI with TestClient
Fixtures Parametrize and Organization
Fixtures Parametrize and Organization - Lab Exercises
@pytest.fixture with setup/teardown and yield, scope (function/session), @pytest.mark.parametrize with multiple inputs, conftest.py for shared fixtures, test directory structure mirroring src, database fixtures with in-memory SQLite
Mocking and Testing External Dependencies
Mocking and Testing External Dependencies - Lab Exercises
What to mock (external APIs, time, not your own code), unittest.mock (patch/MagicMock/return_value/side_effect), respx for HTTP mocking, freezegun pattern for time, when NOT to mock
Type Annotations and mypy
Type Annotations and mypy - Lab Exercises
Type hints basics (str/int/float/bool/None), collection types (list[str]/dict[str,int]/tuple), Optional and Union with | syntax, advanced types (TypeAlias/TypedDict/Protocol/Callable), running mypy and fixing errors
Linting Formatting and CI Pipelines
Linting Formatting and CI Pipelines - Lab Exercises
ruff for linting+formatting (ruff check/ruff format), pyproject.toml centralized config, pre-commit hooks, CI pipeline concepts (lint/typecheck/test/coverage), pytest-cov for coverage reports
Capstone Briefing Quality Retrofit
Capstone Quality Retrofit
Capstone: retrofit quality onto untested FastAPI app - add type annotations (pass mypy strict), write tests (80%+ coverage) with fixtures and parametrize, mock external API, configure ruff, create pyproject.toml, pass full pipeline: ruff check and mypy and pytest --cov