From 1ed46f2879108a9f59569abc92b127edfa6bda99 Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Sat, 9 Jun 2012 15:49:37 +0100 Subject: reset_mock now resets magic method mocks --- mock.py | 1 + tests/testmagicmethods.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/mock.py b/mock.py index ffa4900..2b9bb30 100644 --- a/mock.py +++ b/mock.py @@ -764,6 +764,7 @@ class NonCallableMock(Base): # but not method calls _check_and_set_parent(self, value, None, name) setattr(type(self), name, value) + self._mock_children[name] = value elif name == '__class__': self._spec_class = value return diff --git a/tests/testmagicmethods.py b/tests/testmagicmethods.py index 5140ea3..ef0f16d 100644 --- a/tests/testmagicmethods.py +++ b/tests/testmagicmethods.py @@ -426,6 +426,14 @@ class TestMockingMagicMethods(unittest2.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) + + @unittest2.skipUnless(sys.version_info[:2] >= (2, 6), "__dir__ not available until Python 2.6 or later") def test_dir(self): -- cgit v1.2.1