]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import sys |
2 | ||
3 | try: | |
4 | from mock import Mock, patch | |
5 | except ImportError: | |
6 | from unittest.mock import Mock, patch | |
7 | ||
8 | ||
9 | class MockRadosError(Exception): | |
10 | def __init__(self, message, errno=None): | |
11 | super(MockRadosError, self).__init__(message) | |
12 | self.errno = errno | |
13 | ||
14 | def __str__(self): | |
15 | msg = super(MockRadosError, self).__str__() | |
16 | if self.errno is None: | |
17 | return msg | |
18 | return '[errno {0}] {1}'.format(self.errno, msg) | |
19 | ||
20 | ||
21 | def pytest_configure(config): | |
22 | sys.modules.update({ | |
23 | 'rados': Mock(Error=MockRadosError, OSError=MockRadosError), | |
24 | 'rbd': Mock(), | |
25 | 'cephfs': Mock(), | |
26 | }) | |
27 | ||
28 | # we need the following patches to fix the issue of multiple inheritance when | |
29 | # one of the base classes is being mocked. | |
30 | # Error example: | |
31 | # TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) \ | |
32 | # subclass of the metaclasses of all its bases | |
33 | class _BaseMgrModule: | |
34 | pass | |
35 | ||
36 | patcher = patch("ceph_module.BaseMgrStandbyModule", new=_BaseMgrModule) | |
37 | patcher.start() | |
38 | patcher = patch("ceph_module.BaseMgrModule", new=_BaseMgrModule) | |
39 | patcher.start() |