Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 543 Bytes

File metadata and controls

22 lines (18 loc) · 543 Bytes

Python Unittest Autospec

import unittest
import unittest.mock as mock

class Apple:
    def __init__(self):
        self._weight = 233

    def weight(self):
        print(self._weight)
        return self._weight

class TestAutospec(unittest.TestCase):
    def test_autospec(self):
        mocked_apple_class = mock.create_autospec(Apple)
        weight = mocked_apple_class().weight()
        mocked_apple_class().weight.assert_called_once_with()
        self.assertIsInstance(weight, mock.MagicMock)