02.07

Testing with pytest

skillmaxingPython with AITesting with pytest
Visual lesson

Testing with pytest

Included with Pro · 4:04
Lessons · 1,064 words

A test in pytest is a function whose name starts with test_, in a file whose name starts with test_, containing at least one assert. There is no base class to inherit and no special assertion library to learn. When an assert fails, pytest rewrites it to show the values on each side, so assert ticket.status is Status.ESCALATED failing tells you that the status was Status.OPEN without you writing a message.

That minimalism is why pytest wins. The rest of the framework is three ideas layered on top: fixtures for the things a test needs before it starts, parametrize for running one test body over many inputs, and plugins, of which pytest-asyncio is the one an AI backend cannot do without.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online