diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-06-09 15:45:05 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-06-09 15:45:05 +0100 |
commit | 2d05a53552df9ddc66807180f01ffc0ad4dda13f (patch) | |
tree | 9b8ccfe437fe5030de3538e5f5828b7dff14bb44 | |
parent | fb02acb15d2667242a35fecc79eaa17819f61c8a (diff) | |
download | mock-2d05a53552df9ddc66807180f01ffc0ad4dda13f.tar.gz |
MagicMock.reset_mock on an autospec created mock no longer crashes
-rw-r--r-- | docs/changelog.txt | 5 | ||||
-rw-r--r-- | mock.py | 4 | ||||
-rw-r--r-- | tests/testhelpers.py | 7 |
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 -------------------------------- @@ -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): |