Repaso
EspaƱol
TestingAdvancedTST-18

What does patch(..., autospec=True) add?

Options

  1. Faster mocks, since they skip the real object
  2. The mock uses the real signature, so bad calls fail (Correct option)
  3. Automatic assertions on every call that is made
  4. 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.

Key terms

Practice this question in Repaso