MCPcopy Create free account
hub / github.com/python/cpython / test_configure_mock

Method test_configure_mock

Lib/test/test_unittest/testmock/testmock.py:1112–1130  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1110
1111
1112 def test_configure_mock(self):
1113 mock = Mock(foo='bar')
1114 self.assertEqual(mock.foo, 'bar')
1115
1116 mock = MagicMock(foo='bar')
1117 self.assertEqual(mock.foo, 'bar')
1118
1119 kwargs = {'side_effect': KeyError, 'foo.bar.return_value': 33,
1120 'foo': MagicMock()}
1121 mock = Mock(**kwargs)
1122 self.assertRaises(KeyError, mock)
1123 self.assertEqual(mock.foo.bar(), 33)
1124 self.assertIsInstance(mock.foo, MagicMock)
1125
1126 mock = Mock()
1127 mock.configure_mock(**kwargs)
1128 self.assertRaises(KeyError, mock)
1129 self.assertEqual(mock.foo.bar(), 33)
1130 self.assertIsInstance(mock.foo, MagicMock)
1131
1132
1133 def assertRaisesWithMsg(self, exception, message, func, *args, **kwargs):

Callers

nothing calls this directly

Calls 7

MockClass · 0.90
MagicMockClass · 0.90
assertIsInstanceMethod · 0.80
configure_mockMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
barMethod · 0.45

Tested by

no test coverage detected