-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
26 lines (21 loc) · 910 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import builtins
import os
import re
import unittest.mock
def dyld_find_mock(lib_filename):
# https://github.com/python/cpython/blob/master/Lib/ctypes/macholib/dyld.py#L116
lib_name = re.match(r'^(lib\w+)\.\w+(\.\d+)?$', lib_filename).group(1)
return os.path.join(os.sep, 'usr', 'lib', lib_name + '.dylib')
_BUILTIN_IMPORT = builtins.__import__
def import_mock(name, *args, **kwargs):
try:
return _BUILTIN_IMPORT(name, *args, **kwargs)
except ModuleNotFoundError as exc:
if name == 'ctypes.macholib.dyld': # only available on mac
dyld_module = unittest.mock.MagicMock()
dyld_module.dyld_find = dyld_find_mock
return dyld_module
raise exc
# required for tests/dlinfo_macosx_mock_test.py and doctests in dlinfo/_macosx.py.
# @pytest.fixture(autouse=True) does not run before import statements.
builtins.__import__ = import_mock