Test Python code with pytest fixtures and parametrization
8 steps · about 2 h 30 min · Beginner
- Run pytest and select tests (article, pytest docs, 15 min)
Teaches the command-line options you will use every day.
- Skip tests and mark expected failures (article, pytest docs, 15 min)
Shows how to handle tests that cannot run everywhere.
- Learn fixtures from the reference (article, pytest docs, 30 min)
Explains fixture scope, autouse and teardown precisely.
- Run one test over many inputs (article, pytest docs, 20 min)
Replaces copy-pasted tests with a data table.
- Use temporary files and directories (article, pytest docs, 10 min)
Lets file-handling tests run safely and cleanly.
- Inspect log output in tests (article, pytest docs, 15 min)
Lets you assert on logging without printing.
- Organise tests with marks (article, pytest docs, 15 min)
Lets you skip, expect failures and select slow tests.
- Practise with an end-to-end pytest tutorial (article, Real Python, 30 min)
Ties the pieces together in a worked example.