Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from unittest.mock import patch
- from unittest import TestCase, main
- class MockedClass:
- def real_method(self):
- print('___')
- print('Реальный метод')
- print('Выполняется реальная работа')
- print('___')
- return 'OK'
- class MyTestCase(TestCase):
- def test_real_method(self):
- mocked_class = MockedClass()
- result = mocked_class.real_method()
- self.assertEqual(result, 'OK')
- @patch('__main__.MockedClass.real_method')
- def test_real_method_mocked(self, mock_real_method):
- mock_real_method.return_value = 'OK'
- mocked_class = MockedClass()
- result = mocked_class.real_method()
- self.assertEqual(result, 'OK')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement