Skip to main content

Writing tests with pytest

Write unit tests with pytest, use fixtures and parametrised tests, fake slow or external parts, and know what to test first.

Beginner 3 · Data and toolsabout 2 hours5 sections

Quick answer

A test is code that runs your code with a known input and checks the output. pytest finds functions named test_ and reports which pass, so you can change code knowing you have not broken it.

Why it matters

Tests let you change code without fear, catch bugs before users do, and show reviewers that your change works. Interviewers ask how you test, and AI teams test both their code and their prompts.

Sign up free to read the whole lesson

The rest of this lesson: 5 parts, video lessons, the best course, practice and a quick check. It is free, takes a few seconds and needs no card.

Accounts are for learners aged 18 and over. Under 18? The quick answer and the first part of every lesson stay open: browse lessons by topic.

Software engineeringBeginner 3: Data and toolsUnit testpytestTest fixtureMocking

Track

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.