Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 17.9 — Capstone: Test, Package and Ship It
Python · Example 1 of 2

A test suite built on a fake model

Break the chunker on purpose (change size - overlap to size) and watch which tests fail.

Finish docqa like a professional project: a test suite built on fakes, Ruff and a type checker, a pyproject.toml with a console command and a lock file, a Dockerfile, a README, and a list of what to build next.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a unittest test class with two tests for a function normalise(text) that lowercases and strips text, then run it with a TestResult and print the counts.

02

Use tomllib to read this text and print the project name and version: [project] newline name = "demo" newline version = "1.2.3".

03

Write a function has_secret(text, secret) and a test showing that describe_config-style output never contains the secret string.

Explain it without notes

01

How do fakes and dependency injection make the docqa test suite fast and deterministic?

02

What goes in pyproject.toml, and what does the lock file add?

03

What belongs in a good Dockerfile for a Python tool, and what must never be in the image?

04

Which checks would you run in CI for this project, and in what order?

05

How do pytest fixtures and parametrize improve a test suite compared with plain unittest classes?

A test suite built on a fake model
Sign in to run this example in your browser.

Expected output

ran 5 tests, 0 failures, 0 errors