Fix fake importer for Python 3

Python 3 does not appear to pass all values to the `__import__` builtin
when they do not differ from the defaults. Therefore, the fake import
fails because of missing positional args.

This fix simply uses the defaults from Python 2 and 3's `__import__`
builtin.
This commit is contained in:
Erik Johnson 2017-12-19 12:02:53 -06:00
parent 016ffbe7f8
commit 7d6b679ac4
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -437,7 +437,12 @@ class ForceImportErrorOn(object):
def restore_import_funtion(self):
self.patcher.stop()
def __fake_import__(self, name, globals_, locals_, fromlist, level=-1):
def __fake_import__(self,
name,
globals_={} if six.PY2 else None,
locals_={} if six.PY2 else None,
fromlist=[] if six.PY2 else (),
level=-1 if six.PY2 else 0):
if name in self.__module_names:
importerror_fromlist = self.__module_names.get(name)
if importerror_fromlist is None:
@ -453,7 +458,6 @@ class ForceImportErrorOn(object):
)
)
)
return self.__original_import(name, globals_, locals_, fromlist, level)
def __enter__(self):