ttfw: allow relative imports in test scripts

pull/5307/head
Ivan Grokhotkov 2020-05-02 01:02:07 +02:00
rodzic 7d74cc4255
commit 3fe4adc98d
1 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -61,11 +61,15 @@ def load_source(path):
return __LOADED_MODULES[path]
except KeyError:
try:
dir = os.path.dirname(path)
sys.path.append(dir)
from importlib.machinery import SourceFileLoader
ret = SourceFileLoader(load_name, path).load_module()
except ImportError:
# importlib.machinery doesn't exists in Python 2 so we will use imp (deprecated in Python 3)
import imp
ret = imp.load_source(load_name, path)
finally:
sys.path.remove(dir)
__LOADED_MODULES[path] = ret
return ret