Question
When should a Python developer choose pytest Fixtures and monkeypatch deliberately?
- Choose pytest Fixtures and monkeypatch mainly when you want to postpone validation and fix issues manually later.
- Use fixtures for shared test state and monkeypatch at boundaries such as environment reads, clocks, or external-call wrappers.
- Choose pytest Fixtures and monkeypatch whenever you want the code to look more advanced, even if the design gets less clear.
- Choose pytest Fixtures and monkeypatch only to avoid modeling the real data shape or domain contract explicitly.
Hint
Think about the production scenario where the choice genuinely improves the code.
Answer and rationale
Correct answer: B. Use fixtures for shared test state and monkeypatch at boundaries such as environment reads, clocks, or external-call wrappers.
Use fixtures for shared test state and monkeypatch at boundaries such as environment reads, clocks, or external-call wrappers. Interviewers often ask this to see whether you can connect the concept to real design decisions.
Track: Python