Search the archive

14,355 indexed articles, 13,283 of them summarised by us.

Articles
14,355
Research papers
91,965
Models priced
2,249
Providers
163

2 results for “pytest.mark.parametrize”

Newest and most relevant first

Tips for getting coding agents to write good Python tests

Developers using coding agents can directly apply Simon Willison's concrete prompting tactics to get higher-quality Python test suites with less manual cleanup.

Simon Willison, a well-known programmer and writer, shared tips on his blog for getting AI coding assistants like Claude to write good Python tests. His main advice: name specific tools such as pytest-httpx for mocking network calls, and work in a project that already has a clean test suite, because the AI copies existing patterns. He also recommends pointing the agent at an example repository, like his datasette-enrichments project on GitHub, so it can imitate the testing style.

Willison's post argues that AI-written test quality depends mostly on project hygiene rather than clever prompting: agents mirror the patterns already in your codebase. Teams adopting AI coding tools should invest in clean, well-patterned pytest suites before delegating test writing, since duplicated setup code is the main anti-pattern to police. No costs, benchmarks or timelines are given; the value is practical workflow guidance for engineering leads.

Willison works in Python because pytest is heavily represented in model training data, so Claude reliably knows commands like 'use pytest-httpx to mock the endpoints' or 'refactor to pytest.mark.parametrize' and 'extract common setup into a fixture'. The main anti-pattern he flags is duplicated test setup code, which he tolerates less in implementation than tests. His strongest tactic is pasting a prompt telling the agent to clone a reference repo, e.g. datasette/datasette-enrichments, to /tmp and imitate its testing patterns.

Simon Willison’s Weblog →

TIL: Subtests in pytest 9.0.0+

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.

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.

Simon Willison’s Weblog →