Pytest.
Python testing with Pytest — fixtures, parametrize, plugins, mocking, coverage, and CI integration.
Beginner
Start here — no prior experience needed
Your First Pytest Test
Write a test, run it, and read pytest's output — including the assertion introspection that makes a failure tell you what actually went wrong.
Pytest Fixtures
Replace repeated setup with fixtures, control how often they run with scope, and watch teardown happen after a test fails.
Parametrized Tests in Pytest
Run one test function against many inputs with parametrize, name the cases so failures stay readable, and parametrize a fixture to rerun a whole file.
Pytest Markers, Skipping, and xfail
Tag tests with custom markers, select them with -m, skip conditionally, and record a known bug as xfail so it fails the build the day it is fixed.
Test Layout and Pytest Configuration
Fix the ModuleNotFoundError every new pytest project hits, understand rootdir and conftest, and put your defaults in pyproject.toml instead of your shell history.
Intermediate
For developers with core concepts down
Monkeypatching and Mocking in Pytest
Replace network calls, clocks and environment variables in a test using monkeypatch and unittest.mock, and learn why patching the wrong name silently does nothing.
Testing Files, Output, and Logs with Pytest
Use tmp_path for real files that clean themselves up, capsys to assert on printed output, and caplog to test the log lines your code emits.
Measuring Coverage with pytest-cov
Run coverage from pytest, read the missing-lines report, turn on branch coverage, and see why a suite at 100% can still miss the bug.
Advanced
Production-grade patterns for experienced engineers
Pytest Plugins and Hooks
Add your own command-line flags, modify collection, react to test results, and package the whole thing as an installable pytest plugin.
Fast, Deterministic Pytest Suites
Find the slow tests with --durations, run them in parallel with xdist, expose order dependence with random ordering, and wire the suite into CI properly.