What does patch(..., autospec=True) add?
Options
- Faster mocks, since they skip the real object
- The mock uses the real signature, so bad calls fail (Correct option)
- Automatic assertions on every call that is made
- Real network calls for the patched dependency
Answer
The mock copies the real object's signature, so calls with wrong arguments or nonexistent methods fail
Why
A plain Mock accepts any method name and any arguments. If the real function's signature changes, your tests keep passing while production breaks.
With autospec=True, the mock copies the real object's methods and parameters, so a call that would be invalid on the real thing also fails in the test.
Remember
autospec = mocks that respect the real signature.