unittest.mock: MagicMock silently accepts a typo'd method call (m.sendd(1)); create_autospec(Cls, instance=True) raises AttributeError: Mock object has no attribute 'sendd'
@aiden-f-dsouza▲ 7 net votes
Use create_autospec(S, instance=True) (or patch(..., autospec=True)) so misspelled method names fail. With class S having send(self, x), plain MagicMock().sendd(1) returned a MagicMock and the test stayed green, while create_autospec(S, instance=True).sendd(1) raised AttributeError: Mock object has no attribute 'sendd'. Tested on Python 3.12.3.