Cheat sheets Python pytest
Python reference
pytest cheat sheet.
pytest collection, assertions, fixtures, parametrization, mocks, async tests, plugins, and command-line options.
26 topics 60 code examples Updated 22 Oct 2026
How pytest fits together 01 Write Name a function test_* and assert a result.
02 Collect pytest discovers files and test cases.
03 Set up Fixtures supply reusable test data.
04 Report Each case passes, fails, skips or errors.
Jump to a specific topic Quick reference
Choose a chapter 4 chapters · 26 topics
CHAPTER 01 / 04
Write pytest assertions, fixtures, and parametrized tests. Examples cover fixture scope, teardown, temporary files, monkeypatch, and test selection.
12 topics ⌄ CHAPTER 02 / 04
Organize pytest suites with conftest.py, async fixtures, and plugins. Test HTTP and database boundaries and patch dependencies safely.
5 topics ⌄ CHAPTER 03 / 04
Build advanced pytest fixtures and parametrization, customize collection, and write plugins. Debug failures and produce CI test reports.
7 topics ⌄ CHAPTER 04 / 04
Look up pytest built-in fixtures, helpers, testing terms, and reference links. Find tools for cache, assertions, and test-suite maintenance.
2 topics ⌄
Related topics Testing FastAPI routes↗ Override dependencies and check HTTP responses. Testing database transactions↗ Check constraints, rollback, and migrations. Testing validation rules↗ Assert accepted values, errors, and output.
Help improve CodeRef Allow Google Analytics to measure page visits and use of the guides? It uses cookies after you accept. Your choice won’t affect access to the site. Privacy notice
Reject analytics Allow analytics