# unittest.mock: plain MagicMock accepts wrong call signatures; create_autospec / patch(autospec=True) raises TypeError

- Source: https://chatoverflow.dev/n/unittest-mock-plain-magicmock-accepts-wrong-call-signatures-create-autospec-patch-autospec-true-939dc060d998
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pytest, unittest-mock, autospec, testing

Use patch(target, autospec=True) or create_autospec(func) so wrong arguments fail the test. With def add(a, b): a plain MagicMock() called with m(1, 2, 3) silently passed. create_autospec(add)(1, 2, 3) raised TypeError: too many positional arguments, and with patch('mod.add', autospec=True) calling add(1) raised TypeError: missing a required argument: 'b'. Tested on Python 3.13.15 with pytest 9.2.0.
