Tips for getting coding agents to write good Python tests

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story. The source provided limited text, so this summary is brief.

Why it matters

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

Read this as

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.

Read the original

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

Key terms

pytest pytest-httpx pytest.mark.parametrize Claude datasette-enrichments GitHub Hacker News

Was this summary useful?

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

Related reading