AI Instructor Live Labs Included

Python Testing and Code Quality

Write reliable Python with pytest, type annotations, mypy, ruff, and CI pipeline patterns. Test a real FastAPI application.

Intermediate
10h 45m
12 Lessons
PY-600
Python Testing and Code Quality Badge

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
01
AI Lesson
AI Lesson

pytest Fundamentals

35m
02
Lab Exercise
Lab Exercise

pytest Fundamentals - Lab Exercises

1h 15m 1 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

pytest Fundamentals: Building Robust Test Suites pytest Fundamentals: Building Robust Test Suites ~30 min
03
AI Lesson
AI Lesson

Fixtures Parametrize and Organization

35m
04
Lab Exercise
Lab Exercise

Fixtures Parametrize and Organization - Lab Exercises

1h 15m 1 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

Fixtures Parametrize and Organization Fixtures Parametrize and Organization ~30 min
05
AI Lesson
AI Lesson

Mocking and Testing External Dependencies

35m
06
Lab Exercise
Lab Exercise

Mocking and Testing External Dependencies - Lab Exercises

1h 15m 1 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

Mocking and Testing External Dependencies Mocking and Testing External Dependencies ~30 min
07
AI Lesson
AI Lesson

Type Annotations and mypy

30m
08
Lab Exercise
Lab Exercise

Type Annotations and mypy - Lab Exercises

1h 15m 1 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

Type Annotations and mypy for Code Quality Type Annotations and mypy for Code Quality ~30 min
09
AI Lesson
AI Lesson

Linting Formatting and CI Pipelines

30m
10
Lab Exercise
Lab Exercise

Linting Formatting and CI Pipelines - Lab Exercises

1h 15m 1 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

Building Production-Ready Python Applications with Linting, Formatting, and CI Pipelines Building Production-Ready Python Applications with Linting, Formatting, and CI Pipelines ~30 min
11
AI Lesson
AI Lesson

Capstone Briefing Quality Retrofit

30m
12
Lab Exercise
Lab Exercise

Capstone Quality Retrofit

1h 15m 1 Exercises

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

Exercise 1 Exercise 1 ~30 min

This course includes:

  • 24/7 AI Instructor Support
  • Live Lab Environments
  • 6 Hands-on Lessons
  • 6 Months Access
  • Completion Badge
  • Certificate of Completion
Python Testing and Code Quality Badge

Earn Your Badge

Complete all lessons to unlock the Python Testing and Code Quality achievement badge.

Category
Skill Level Intermediate
Total Duration 10h 45m
Python Testing and Code Quality Badge
Achievement Badge

Python Testing and Code Quality

Demonstrates proficiency in testing with pytest, type checking with mypy, and code quality with ruff.

Course Python Testing and Code Quality

Skills You'll Earn

Python pytest mypy ruff Mocking CI/CD Code Coverage

Complete all lessons in this course to earn this badge