| Quick Reference Pytest CheatsheetPytest on one page — fixtures, raises, parametrize, and the traps around scope, approx, and collection. 10 sections 10 tables 14 code snippets A testPlain assert One node What gets collected
This page is pytest. Selenium and unittest-style suites are left out. AssertionsFloats need a tolerance What to write
ExceptionsOnly the raising line inside Match the error
FixturesSetup, then teardown Default scope How a fixture is used
ScopesWider cannot ask for narrower How long the value lives
Patch and pathsAn env var for this test A directory for this test Built-in fixtures
ParametersOne function, three cases Rows
Skip and selectDo not run this one An expected failure Marks and the command line
Interview trapsLeave the with block Collection Traps worth memorising
How to use this page: name the test |