From: Ricardo Dias Date: Wed, 16 Oct 2019 14:45:11 +0000 (+0100) Subject: mgr/dashboard: tests: fix mocking of MgrModule and MgrStandbyModule classes X-Git-Tag: v15.1.0~694^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a5c70a7f5f7e9109e623cdc15d153ad14d8e1ecf;p=ceph.git mgr/dashboard: tests: fix mocking of MgrModule and MgrStandbyModule classes Signed-off-by: Ricardo Dias --- diff --git a/src/pybind/mgr/dashboard/conftest.py b/src/pybind/mgr/dashboard/conftest.py index b7fa2d1c291..8b5e9ac9c36 100644 --- a/src/pybind/mgr/dashboard/conftest.py +++ b/src/pybind/mgr/dashboard/conftest.py @@ -1,9 +1,9 @@ import sys try: - from mock import Mock + from mock import Mock, patch except ImportError: - from unittest.mock import Mock + from unittest.mock import Mock, patch class MockRadosError(Exception): @@ -24,3 +24,16 @@ def pytest_configure(config): 'rbd': Mock(), 'cephfs': Mock(), }) + + # we need the following patches to fix the issue of multiple inheritance when + # one of the base classes is being mocked. + # Error example: + # TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) \ + # subclass of the metaclasses of all its bases + class _BaseMgrModule: + pass + + patcher = patch("ceph_module.BaseMgrStandbyModule", new=_BaseMgrModule) + patcher.start() + patcher = patch("ceph_module.BaseMgrModule", new=_BaseMgrModule) + patcher.start()