summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-06-09 15:49:37 +0100
committerMichael Foord <michael@voidspace.org.uk>2012-06-09 15:49:37 +0100
commit1ed46f2879108a9f59569abc92b127edfa6bda99 (patch)
tree4ea1fb5502e34fed27d559978bc42649ef97ee53
parent2d05a53552df9ddc66807180f01ffc0ad4dda13f (diff)
downloadmock-1ed46f2879108a9f59569abc92b127edfa6bda99.tar.gz
reset_mock now resets magic method mocks
-rw-r--r--mock.py1
-rw-r--r--tests/testmagicmethods.py8
2 files changed, 9 insertions, 0 deletions
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):