summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-06-09 15:45:05 +0100
committerMichael Foord <michael@voidspace.org.uk>2012-06-09 15:45:05 +0100
commit2d05a53552df9ddc66807180f01ffc0ad4dda13f (patch)
tree9b8ccfe437fe5030de3538e5f5828b7dff14bb44
parentfb02acb15d2667242a35fecc79eaa17819f61c8a (diff)
downloadmock-2d05a53552df9ddc66807180f01ffc0ad4dda13f.tar.gz
MagicMock.reset_mock on an autospec created mock no longer crashes
-rw-r--r--docs/changelog.txt5
-rw-r--r--mock.py4
-rw-r--r--tests/testhelpers.py7
3 files changed, 15 insertions, 1 deletions
diff --git a/docs/changelog.txt b/docs/changelog.txt
index 59e3df3..cc990f2 100644
--- a/docs/changelog.txt
+++ b/docs/changelog.txt
@@ -7,6 +7,11 @@ CHANGELOG
2012/XX/XX Version 1.0.0 alpha 3
--------------------------------
+* BUGFIX: calling `MagicMock.reset_mock` wouldn't reset magic method mocks
+* BUGFIX: calling `reset_mock` on a `MagicMock` created with autospec could
+ raise an exception
+
+
2012/05/04 Version 1.0.0 alpha 2
--------------------------------
diff --git a/mock.py b/mock.py
index 88ceec2..ffa4900 100644
--- a/mock.py
+++ b/mock.py
@@ -30,7 +30,7 @@ __all__ = (
)
-__version__ = '1.0a2'
+__version__ = '1.0a3'
import pprint
@@ -608,6 +608,8 @@ class NonCallableMock(Base):
self.method_calls = _CallList()
for child in self._mock_children.values():
+ if isinstance(child, _SpecState):
+ continue
child.reset_mock()
ret = self._mock_return_value
diff --git a/tests/testhelpers.py b/tests/testhelpers.py
index b3b31ac..e788da8 100644
--- a/tests/testhelpers.py
+++ b/tests/testhelpers.py
@@ -359,6 +359,13 @@ class SpecSignatureTest(unittest2.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):