11import builtins
22import ctypes
33import ctypes .util
4+ import importlib
45import os
56import types
67import unittest .mock
78
89import pytest
910
11+ import dlinfo
12+
1013BUILTIN_IMPORT = builtins .__import__
1114
1215
13- # pytest: disable=redefined-outer-name
1416def dyld_find_mock (name ):
1517 # https://github.com/python/cpython/blob/master/Lib/ctypes/macholib/dyld.py#L116
1618 return os .path .join (os .sep , 'lib' , name )
@@ -24,11 +26,12 @@ def import_mock(name, *args):
2426 return BUILTIN_IMPORT (name , * args )
2527
2628
29+ # pylint: disable=redefined-outer-name
2730@pytest .fixture
2831def dlinfo_module_mac () -> types .ModuleType :
2932 with unittest .mock .patch ('sys.platform' , 'darwin' ):
3033 with unittest .mock .patch ('builtins.__import__' , import_mock ):
31- dlinfo_module = __import__ ( ' dlinfo' )
34+ dlinfo_module = importlib . reload ( dlinfo )
3235 assert dlinfo_module .DLInfo .__module__ == 'dlinfo._macosx'
3336 return dlinfo_module
3437
@@ -44,6 +47,6 @@ def test_dlinfo_path(dlinfo_module_mac, lib_name):
4447 if not lib_filename :
4548 pytest .xfail ('lib{} not found' .format (lib_name ))
4649 lib = ctypes .cdll .LoadLibrary (lib_filename )
47- dlinfo = dlinfo_module_mac .DLInfo (lib )
48- assert lib_filename == os .path .basename (dlinfo .path )
49- assert os .path .join (os .sep , 'lib' ) == os .path .dirname (dlinfo .path )
50+ lib_info = dlinfo_module_mac .DLInfo (lib )
51+ assert lib_filename == os .path .basename (lib_info .path )
52+ assert os .path .join (os .sep , 'lib' ) == os .path .dirname (lib_info .path )
0 commit comments