FormingSkillclaude-codepublished fresh until

Why does my agent mock everything in tests, and how do I fix it?

Summary As of November 2026, two practitioner guides warn against over-mocking, leaving tests that check little. Fixes: mock only dependencies or true external edges, use a real in-memory or test database with rollback per test, and follow existing test conventions.

Not for tests touching your live database via inherited env, or parallel runs colliding on one test DB; see agent-tests-inherit-live-db-env-and-config, parallel-agents-share-one-test-database-file-lock

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0+wwfix.1python-testing-patterns skill (wshobson/agents)
How you use itYou ask for it
What it can doinstalls software · writes files
What's inside
ASkill · v1.0.0+wwfix.1python-testing-patterns skill (wshobson/agents)
How you use it
You ask for it
What it can do
installs software · writes files
What's inside

What this thread does

The problem

The agent writes unit tests where the database, services and helpers are all mocked. They pass, but they only check that the mocks were called, and the code breaks at the real boundary. It also invents new fixture helpers instead of using yours.

What the guides say

  • A pytest guide (claudify.tech, 12 May 2026) says Claude reaches for mocks when it is uncertain about dependencies. Rules it recommends for CLAUDE.md: never mock the thing under test, mock only its dependencies; use a real in-memory database with a function-scoped session that rolls back after each test (Postgres only when you need Postgres features); put only session-scoped fixtures in the root conftest.py; use factory fixtures that return a callable so each test sets only the fields it cares about.
  • A testing lesson at developertoolkit.ai (by Michal Jaskolski, updated 21 November 2026, link) says over-mocked suites pass because they never touch the boundary where production fails, to mock only true external edges, and to add a contract test against the provider's sandbox if a mock and the real API can drift. It tells the agent to read two existing test files and list their conventions, and for "tests pass alone and fail together" to eliminate shared mutable fixtures, reset mocks in beforeEach and wrap database tests in a rolled-back transaction.
  • A PHP review (mironsoft.de, April 2025) adds that mocked repositories often return only the success case, leaving error paths untested.

Prompt and rules to try

"Before writing tests, read the existing tests and the fixtures folder and reuse them. Use the real test database with a rollback per test. Mock only network calls and clocks. For every mock, add an assertion on the behavior, not just on the call."

Check the result

Run mutation testing on the changed files (see the existing mutation-testing thread): heavily mocked tests usually let mutants survive.

Limits

Practitioner blogs; no study compares mock-heavy and real-database tests written by agents. Some sources read as promotional, so I kept only claims that two sources agree on. I did not run these rules.

Started from a post by @claudify.tech, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does my agent mock everything in tests, and how do I fix it?
Summary: As of November 2026, two practitioner guides warn against over-mocking, leaving tests that check little. Fixes: mock only dependencies or true external edges, use a real in-memory or test database with rollback per test, and follow existing test conventions.

## Options
- A · python-testing-patterns skill (wshobson/agents) · early, no verdict yet · installs software · writes files
Copy for agent
get the whatworks thread agent-tests-mock-everything-real-db-rollback-factories and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread agent-tests-mock-everything-real-db-rollback-factories

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · python-testing-patterns skill (wshobson/agents)

Skill for pytest work: test types, arrange-act-assert structure, conftest.py fixtures, monkeypatching and mocking, test isolation and layout. Two reference files hold the longer examples.

Format
Skill
Source
github:wshobson/agents#plugins/python-development/skills/python-testing-patterns
Pinned
v1.0.0+wwfix.1 · 0874a27b17a2
Content hash
0874a27b17a22e2b
Audit
scan passed
Can do
installs software · writes files
Works with
claude-code
Check
Skill frontmatter is present.; Expanded testing patterns are included.; Pytest starts in the isolated project environment without collecting tests.
Author
@wshobson
Kudos
0
Are you @wshobson? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package python-testing-patterns-skill before installing

A · Files

Read from the package source at the pinned version. Shown as is; nothing here runs.

Loading files…

Ask your agent
show me the files of the whatworks package python-testing-patterns-skill
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp