Mock Django test boundaries safely with override_settings, pytest settings, autospecced unittest.mock objects, output/input capture, requests-mock, VCR.py, outbound HTTP blocking, and time-freezing tools.
SkillScore95Maintained
Automatic
◆QA & Test Engineering pack
Last verified 8/15/2026
What it changes
Passed 21 of 22 test cases with the skill, and 17 of 22 without it.
Without skill77%
With skill95%
Checks it passed that the model alone missed
The response uses requests-mock for intercepting HTTP calls.
The response specifies using autospec=True when creating the mock.
The response uses requests-mock to intercept outbound HTTP requests.
and 1 more in the full report
4 fixed17 passed either way1 still failing0 broke
Pass-rate lift
+18 pp
Tokens
+4%
Agent turns
0%
Response time
-30%
Model gemini-3.6-flashMeasured 8/15/2026v121 of 22 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 4 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 4
Prompt
We created a mock object for a payment client using `unittest.mock.Mock()`, but typos in method calls like `client.charg()` are silently ignored during tests. What parameter must be passed during mock creation to enforce interface signature checking?
What was checked, without and with the skill
Checked
Without skill
With skill
The response specifies using autospec=True when creating the mock.
Missed
Passed
case-09 · gemini-3.6-flash · 8/15/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md56 lines2 files
Django Targeted Mocking
Mock only at boundaries that are slow, nondeterministic, external, or hard to trigger. Broad mocks can make tests faster while proving less, so prefer framework helpers and interface-checked replacements.
Boundary Workflow
Decide whether mocking is necessary.
Prefer real code for local domain logic.
Mock external HTTP, time, settings, output/input, and expensive service edges.
Patch where the code under test looks up the dependency.
Patch the imported symbol used by the module under test, not the original library path unless that is what the module reads.
Prefer specific tools.
Settings: override_settings, modify_settings, or pytest-django's settings fixture.
Output: io.StringIO, pytest capsys, or command test helpers.
HTTP: requests-mock for hand-authored responses; VCR.py for recorded responses.
Time: pass time as a parameter when possible; otherwise use time-machine or a similar time-specific tool.
Make mocks interface-aware.
Use autospec=True, spec, spec_set, create_autospec, or a small fake object.
Avoid bare Mock/MagicMock when the interface matters.
Block unexpected outbound HTTP.
A normal test run should fail if a test reaches the network unintentionally.
Read mocking-patterns.md for concrete patterns.
Decision Rules
Use Django settings helpers instead of direct assignment to django.conf.settings.
Prefer a hand-built fake or types.SimpleNamespace when only a few attributes are needed.
Use requests-mock for deterministic API responses you control.
Use VCR.py when real recorded responses are valuable and safe to store.
On CI, configure VCR record mode so missing cassettes fail instead of recording.
Mock time consistently across the runtime; do not patch several datetime functions by hand.
Do not mock the component whose behavior the test is meant to prove.