Skip to content

TypeError: super() argument 1 must be type, not MagicMock #110

@amanagr

Description

@amanagr

My test:

class TestController:

    @pytest.fixture(autouse=True)
    def mock_external_classes(self, mocker):
        mocker.patch('zulipterminal.ui.View')

    def test_initialize_controller(self):
        Controller(config_file, theme)

Controller:

class Controller:
    def __init__(self):
        self.view = View()

View:

Class View(urwid.WidgetWrap):
    def __init__(self):
        ...
        super(View, self).__init__(self.main_window())
...

This is the error:

====================================================== test session starts =======================================================
platform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.3, pluggy-0.6.0
rootdir: /home/a/zulip-terminal, inifile:
plugins: pep8-1.0.6, mock-1.7.1, cov-2.5.1
collected 3 items

tests/core/test_core.py F                                                                                                  [ 33%]
tests/helper/test_helper.py ..                                                                                             [100%]

============================================================ FAILURES ============================================================
___________________________________________ TestController.test_initialize_controller ____________________________________________

self = <tests.core.test_core.TestController object at 0x7fe78c304ac8>

    def test_initialize_controller(self):
        config_file = 'path/to/zuliprc'
        theme = 'default'
>       self.controller = Controller(config_file, theme)

tests/core/test_core.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
zulipterminal/core.py:22: in __init__
    self.view = View(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[AttributeError("'View' object has no attribute '_wrapped_widget'") raised in repr()] View object at 0x7fe78c3ccef0>
controller = <zulipterminal.core.Controller object at 0x7fe78c433400>

    def __init__(self, controller: Any) -> None:
        self.controller = controller
        self.model = controller.model
        self.client = controller.client
        self.users = self.model.users
        self.streams = self.model.streams
        self.write_box = WriteBox(self)
>       super(View, self).__init__(self.main_window())
E       TypeError: super() argument 1 must be type, not MagicMock

zulipterminal/ui.py:63: TypeError
=============================================== 1 failed, 2 passed in 0.19 seconds ===============================================
a@a:~/zulip-terminal$ pytest
====================================================== test session starts =======================================================
platform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.3, pluggy-0.6.0
rootdir: /home/a/zulip-terminal, inifile:
plugins: pep8-1.0.6, mock-1.7.1, cov-2.5.1
collected 3 items

tests/core/test_core.py E                                                                                                  [ 33%]
tests/helper/test_helper.py ..                                                                                             [100%]

============================================================= ERRORS =============================================================
__________________________________ ERROR at setup of TestController.test_initialize_controller ___________________________________

self = <tests.core.test_core.TestController object at 0x7f4b4ff8ab00>, mocker = <pytest_mock.MockFixture object at 0x7f4b4ff8ada0>

    @pytest.fixture(autouse=True)
    def mock_external_classes(self, mocker):
        self.client = mocker.patch('zulip.Client')
        self.model = mocker.patch('zulipterminal.model.Model')
>       self.view = mocker.patch.object('zulipterminal.ui.View')

tests/core/test_core.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../.local/lib/python3.5/site-packages/pytest_mock.py:141: in object
    return self._start_patch(self.mock_module.patch.object, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pytest_mock.MockFixture._Patcher object at 0x7f4b4ff8add8>, mock_func = <function _patch_object at 0x7f4b50263488>
args = ('zulipterminal.ui.View',), kwargs = {}

    def _start_patch(self, mock_func, *args, **kwargs):
        """Patches something by calling the given function from the mock
                module, registering the patch to stop it later and returns the
                mock object resulting from the mock call.
                """
>       p = mock_func(*args, **kwargs)
E       TypeError: _patch_object() missing 1 required positional argument: 'attribute'

../.local/lib/python3.5/site-packages/pytest_mock.py:132: TypeError
=============================================== 2 passed, 1 error in 0.19 seconds ================================================
a@a:~/zulip-terminal$ pytest
====================================================== test session starts =======================================================
platform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.3, pluggy-0.6.0
rootdir: /home/a/zulip-terminal, inifile:
plugins: pep8-1.0.6, mock-1.7.1, cov-2.5.1
collected 3 items

tests/core/test_core.py F                                                                                                  [ 33%]
tests/helper/test_helper.py ..                                                                                             [100%]

============================================================ FAILURES ============================================================
___________________________________________ TestController.test_initialize_controller ____________________________________________

self = <tests.core.test_core.TestController object at 0x7f902b688a90>

    def test_initialize_controller(self):
        config_file = 'path/to/zuliprc'
        theme = 'default'
>       self.controller = Controller(config_file, theme)

tests/core/test_core.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
zulipterminal/core.py:22: in __init__
    self.view = View(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[AttributeError("'View' object has no attribute '_wrapped_widget'") raised in repr()] View object at 0x7f902b749e80>
controller = <zulipterminal.core.Controller object at 0x7f902b7b0390>

    def __init__(self, controller: Any) -> None:
        self.controller = controller
        self.model = controller.model
        self.client = controller.client
        self.users = self.model.users
        self.streams = self.model.streams
        self.write_box = WriteBox(self)
>       super(View, self).__init__(self.main_window())
E       TypeError: super() argument 1 must be type, not MagicMock

zulipterminal/ui.py:63: TypeError
=============================================== 1 failed, 2 passed in 0.19 seconds ===============================================

I can't find solution anywhere for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions