def test_must_return_expected_work_value_using_patch_object(self): with patch.object(Helper, 'get_path', return_value='test_path', autospec=True) as GetPathMock: worker = Worker() return_value = worker.work() GetPathMock.assert_called_once() expected = 'test_path' self.assertEqual(expected, return_value)
def test_must_return_expected_work_value(self): with patch('classes.Helper', autospec=True) as HelperMock: worker = Worker() HelperMock.assert_called_once_with('db') HelperMock.return_value.get_path.return_value = 'test_path' return_value = worker.work() expected = 'test_path' self.assertEqual(expected, return_value)