summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorVegard Stikbakke <vegard.stikbakke@gmail.com>2020-01-25 15:44:46 (GMT)
committerChris Withers <chris@withers.org>2020-01-25 15:44:46 (GMT)
commitaef7dc89879d099dc704bd8037b8a7686fb72838 (patch)
tree90685ced511b41f37ea6fc5d6d4eb12f2b7c6575 /Lib/unittest
parent9bfb4a7061a3bc4fc5632bccfdf9ed61f62679f7 (diff)
downloadcpython-aef7dc89879d099dc704bd8037b8a7686fb72838.zip
cpython-aef7dc89879d099dc704bd8037b8a7686fb72838.tar.gz
cpython-aef7dc89879d099dc704bd8037b8a7686fb72838.tar.bz2
bpo-38932: Mock fully resets child objects on reset_mock(). (GH-17409)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py2
-rw-r--r--Lib/unittest/test/testmock/testmock.py14
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index a97542a..beed717 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -592,7 +592,7 @@ class NonCallableMock(Base):
for child in self._mock_children.values():
if isinstance(child, _SpecState) or child is _deleted:
continue
- child.reset_mock(visited)
+ child.reset_mock(visited, return_value=return_value, side_effect=side_effect)
ret = self._mock_return_value
if _is_instance_mock(ret) and ret is not self:
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 1030d12..1329346 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -1636,11 +1636,23 @@ class MockTest(unittest.TestCase):
self.assertNotEqual(m.side_effect, None)
def test_reset_sideeffect(self):
- m = Mock(return_value=10, side_effect=[2,3])
+ m = Mock(return_value=10, side_effect=[2, 3])
m.reset_mock(side_effect=True)
self.assertEqual(m.return_value, 10)
self.assertEqual(m.side_effect, None)
+ def test_reset_return_with_children(self):
+ m = MagicMock(f=MagicMock(return_value=1))
+ self.assertEqual(m.f(), 1)
+ m.reset_mock(return_value=True)
+ self.assertNotEqual(m.f(), 1)
+
+ def test_reset_return_with_children_side_effect(self):
+ m = MagicMock(f=MagicMock(side_effect=[2, 3]))
+ self.assertNotEqual(m.f.side_effect, None)
+ m.reset_mock(side_effect=True)
+ self.assertEqual(m.f.side_effect, None)
+
def test_mock_add_spec(self):
class _One(object):
one = 1