/dev10x-coding:py-mockitofrom dev10x-coding
Writes pytest tests using python-mockito and pytest-mockito: stub collaborator classes with when(), verify calls with verify(), capture arguments with captor(), and clean up with unstub(). For DI codebases where stubbing classes is preferred over unittest.mock.
Ships in dev10x-coding. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Announce: "Using dev10x-coding:py-mockito to write mockito-based tests."
This skill follows references/task-orchestration.md patterns.
REQUIRED: Create a task at invocation. Execute at startup:
TaskCreate(subject="Apply mockito test patterns", activeForm="Writing mockito tests")Mark completed when done: TaskUpdate(taskId, status="completed")
python-mockito provides a Java-Mockito-inspired stubbing and
verification API for Python tests. Combined with pytest-mockito,
it integrates with pytest fixtures. Its key advantage over
unittest.mock: a stub can target a class, so every instance a
dependency-injection container resolves picks it up — no need to
reach the exact object the code under test will receive. Instances,
modules and managers can be stubbed too when that is the seam you
have.
Core philosophy: stub collaborator classes so the container returns controlled behavior. Verify interactions by asserting what was called, not how the return value was used.
from mockito import (
ANY, # match any single positional arg
KWARGS, # match any keyword arguments
any_, # typed matcher: any_(list), any_(int)
captor, # capture args for later inspection
mock, # create standalone mock object
unstub, # remove stubs (cleanup)
verify, # assert method was called
verifyZeroInteractions, # assert mock was never touched
when, # stub a method to return/raise
)
| Function | Purpose | Example |
|---|---|---|
when(Cls).method(...).thenReturn(val) | Stub any call | Ellipsis matches all args |
when(Cls).method(x=1).thenReturn(val) | Stub specific call | Named args for precision |
verify(Cls).method(x=1) | Assert called once | Default times=1 |
verify(Cls, times=0).method(...) | Assert never called | Negative assertion |
captor() | Capture argument | Inspect via .value |
mock() | Create mock object | Standalone, no class |
unstub(Cls) | Remove stubs on Cls | Or unstub() for all |
Read only the file the current test needs:
| Need | Reference |
|---|---|
when() stubs, matchers, thenReturn/thenRaise, verify(), captor(), mock() | references/stubbing-and-verification.md |
unstub() cleanup, the when fixture, autouse stubs, marker opt-in, result fixtures | references/pytest-patterns.md |
__call__ stubs, fluent-API chains, module functions, private methods, DI container, logger calls | references/advanced-patterns.md |
python-mockito patches its targets globally, so a stub that outlives its test leaks into every later test and turns an unrelated one red.
when fixture (a test or fixture
parameter, not an import). It unstubs at the end of each test, so
function-scoped stubs need no cleanup code.from mockito import when at module level, or a stub set in a
fixture scoped wider than the test (class, module, session).
Then pair it with a targeted unstub:from mockito import unstub, when
@pytest.fixture(scope="class")
def stub_token_repository(token):
when(TokenRepository).get_access_token(...).thenReturn(token)
yield
unstub(TokenRepository)
Prefer unstub(SpecificClass) over a bare unstub() in such a
fixture — the bare form clears every stub, including ones another
fixture still relies on.
| Mistake | Fix |
|---|---|
Importing mockito.when and never unstubbing | Take the when fixture instead, or yield + unstub(Cls) |
| Stubbing an instance you built while the container resolves a fresh one | Stub the class: when(MyClass).method(...) reaches every resolved instance |
Using ... when you need to verify specific args | Use Ellipsis for stubs, named args for verify |
Missing thenReturn() on void stubs | Either when(X).m(...) (implicit None) or .thenReturn(None) |
Calling unstub() without args in a fixture | Clears ALL stubs globally — prefer unstub(SpecificClass) |
Not using captor.all_values for multiple calls | .value returns only the last capture; use .all_values for all |
Forgetting to register mock for verifyZeroInteractions | Call when(module) first to register it for tracking |
[dependency-groups]
dev = [
"mockito",
"pytest-mockito",
]
pytest-mockito auto-provides the when fixture to all tests.
No manual registration or plugin configuration needed.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
mockito, python-testing, dependency-injection, stubbing, verification
npx claudepluginhub dev10x-guru/dev10x-claude --plugin dev10x-coding40 skills in this plugin
/ci-reviewdev10x-coding:ci-reviewUse when a change to a Claude CI review prompt, args file, reviewer agent or CLI pin needs checking before it merges — so you read what the CI code review and PR hygiene check would post on a real PR, with nothing reaching GitHub unless you choose, after reading the report, to share it as one marked replica comment. TRIGGER when: "what would the CI review say", replaying the Claude CI review locally, verifying a review prompt or model change on a PR. DO NOT TRIGGER when: self-reviewing a branch with no PR (use dev10x-coding:review), or reviewing someone's PR and posting (use dev10x-coding:gh-pr-review).
/fanoutdev10x-coding:fanoutProcess multiple independent work items as a worktree-isolated swarm — each item runs the full dev10x-coding:work-on lifecycle inside its own background Agent with isolation="worktree" (under Herdr, its own Herdr workspace and agent). Honors dependencies, minimizes conflicts, auto-advances by default. TRIGGER when: 2+ independent work items need parallel processing (PRs, issues, tickets). DO NOT TRIGGER when: single task or sequential dependency chain (use dev10x-coding:work-on); already running as a swarm child (see recursive-fanout guard).