Fix exception when calling reset_mock on a mock created with autospec

This commit is contained in:
Michael Foord 2012-06-09 17:31:59 +01:00
parent afc0c77b42
commit 75963643b1
3 changed files with 18 additions and 0 deletions

View file

@ -355,6 +355,13 @@ class SpecSignatureTest(unittest.TestCase):
self.assertEqual(mock(), 'foo')
def test_autospec_reset_mock(self):
m = create_autospec(int)
int(m)
m.reset_mock()
self.assertEqual(m.__int__.call_count, 0)
def test_mocking_unbound_methods(self):
class Foo(object):
def foo(self, foo):

View file

@ -345,6 +345,14 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(mock[1][2][3], 3)
def test_magic_method_reset_mock(self):
mock = MagicMock()
str(mock)
self.assertTrue(mock.__str__.called)
mock.reset_mock()
self.assertFalse(mock.__str__.called)
def test_dir(self):
# overriding the default implementation
for mock in Mock(), MagicMock():