Follow-up · depth 1
How would you test Decorators?
How would you test Decorators?
Answers use simple, clear English.
Quick interview answer
Test Decorators with unit checks for the happy path, integration tests for real I/O boundaries, and load/chaos checks so regressions show up before prod. Core idea: Mitigate first, then root-cause. Check symptoms against: Forgetting @wraps; decorator not returning wrapper function..
Detailed answer
Interview answer for testing Decorators: 1) Unit: isolate the pure logic behind Decorators with deterministic fixtures. 2) Integration: exercise real timers/I/O/network boundaries the way production does. 3) Load & soak: prove the event path still meets SLOs under concurrency. 4) Failure injection: break dependencies and assert recovery/backpressure. Best practices to include: Use wraps; accept *args/**kwargs in generic decorators; prefer parameterized factory pattern. Call out mistakes: Forgetting @wraps; decorator not returning wrapper function. Parent context: Mitigate first, then root-cause. Check symptoms against: Forgetting @wraps; decorator not returning wrapper function..
Full explanation
Interviewers want a test strategy, not “I would write tests.” Tie each layer back to how Decorators fails: correctness, latency, and starvation. Decorators wrap functions: @decorator applies decorator(func). functools.wraps preserves __name__/__doc__. Common for logging, auth, caching, retries.
Follow-up questions
Only answered follow-ups are shown — click to open with full answers
Parent context — Decorators
Mitigate first, then root-cause. Check symptoms against: Forgetting @wraps; decorator not returning wrapper function..
View full parent question →