TIL: Subtests in pytest 9.0.0+

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

pytest 9.0.0's new subtests give Python developers a faster, more flexible alternative to @pytest.mark.parametrize, changing how parameterized tests can be written.

Read this as

pytest, a popular tool for testing Python code, added a feature called subtests in version 9.0.0, released November 5, 2025. Instead of writing one test that repeats with different inputs using the old 'parametrize' decorator, developers can now loop inside the test and check each case separately. This is marginally faster and lets tests be built dynamically after setup code runs.

pytest 9.0.0 shipped on November 5, 2025 with a subtests feature as an alternative to the widely used parametrize decorator. Willison reports it runs faster and allows test cases to be generated after setup code executes. Teams doing Python testing could cut test runtime slightly, though nothing breaks immediately; adoption is optional. He used Claude Code to port Datasette tests to the new pattern.

pytest 9.0.0 (released 2025-11-05) introduces subtests via a 'subtests' fixture: wrap assertions in 'with subtests.test()' to get per-case pass/fail reporting. Willison shows a @pytest.mark.parametrize test over app.SETTINGS rewritten as a for-loop with subtests.test(setting=setting.name). Benefits cited: slightly faster execution and programmatic creation of subtests after setup code. He had Claude Code port several Datasette tests (PR #2609) to the pattern.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

pytest 9.0.0 Datasette Claude Code Simon Willison

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading