Use it when designing, executing or reviewing automation tests around Mocks. Keep requirement/risk, test oracle, fixture/environment identity, exercised scope, raw observations and target/workload outcome as separate proof boundaries.
Mocks
Mocks replace external dependencies with controlled test doubles so a unit or narrow component can exercise specified interactions, errors and edge cases deterministically.
1. Mocks replace external systems in tests.
2. Mock at boundaries (APIs, SSH).
3. Recorded responses for realism.
4. Don't over-mock logic.
5. Contract tests to keep mocks honest.
test → mock dependency → assertions
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
unit/component → mocked boundary contract → controlled responses/failures → interaction/output assertions → contract verification against real dependency
Healthy evidence: mocks are narrow, contract-aligned and complemented by real integration tests for important external behavior.
Step 2 Verification path Verify boundary
When testing Mocks, include the cases that usually go wrong: shared mutable fixtures, flaky timing, hidden dependencies, assertion-free smoke checks, production-only assumptions and treating a passing fixture as universal correctness.
Step 3 Failure modes and next checks Narrow the fault
Suspicious evidence: mocks reproduce implementation assumptions rather than the external contract, allowing tests to pass while real integrations fail.
Step 4 Common mistakes Narrow the fault
- Mocks that hide real behaviour.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Mock contract ≠ real dependency behavior.
- Mock call expectation met ≠ downstream side effect occurred.
- Detailed mock interactions ≠ user-visible behavior correct.
- Simulated failure ≠ real timeout/retry semantics reproduced exactly.
python3 -c 'from unittest import mock'— mocking libraryMock in Pester— PowerShell- Recorded API responses (vcr/responses) — replay
ReferenceWhat it is1 section · depth on demand
Core model
Mock only the boundary not under test, model the external contract rather than internal implementation, assert meaningful requests/interactions, simulate representative failures, and back critical mock assumptions with real contract or integration tests.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Mocks show local behavior against the simulated contract only; they cannot show real protocol quirks, timing, authorization or side effects.
In depth
Mocks replace real dependencies — APIs, devices, databases — with test doubles that return controlled responses. They make unit tests fast and deterministic and let you test error handling (timeouts, 500 errors) that is hard to trigger for real.
import responses, requests
@responses.activate
def test_handles_rate_limit():
responses.get("https://api.example.com/devices", status=429, headers={"Retry-After": "1"})
responses.get("https://api.example.com/devices", json={"results": []})
assert fetch_devices() == []
Mocks only prove your code handles the responses you imagined; combine them with integration tests against the real API.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Testing > Mocks. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.pytest.org/en/stable/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Mocks testing proof-boundary map
Fast criteria/scope, execution and effective-outcome proof boundaries for Mocks.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Scope / oracle | Requirement, case, expected result and exercised scope are explicit | A generic green status exists without a trustworthy oracle or coverage boundary |
| Fixture / environment | Data, dependencies and environment versions are reproducible | Shared state, floating versions or stale fixtures make results non-reproducible |
| Effective outcome | Authoritative state/read-back and service-relevant evidence match the expected result | Tool/test/validator success substitutes for effective target or workload proof |
| Limits / next action | Coverage limits, unknowns and failures drive the next narrower check | Unknown evidence becomes pass, retries hide failures or broad success is inferred from one check |