Loading django/utils/module_loading.py +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import os import sys from django.core.exceptions import ImproperlyConfigured from django.utils import six from django.utils.importlib import import_module Loading @@ -19,8 +20,10 @@ def import_by_path(dotted_path, error_prefix=''): try: module = import_module(module_path) except ImportError as e: raise ImproperlyConfigured('%sError importing module %s: "%s"' % ( error_prefix, module_path, e)) msg = '%sError importing module %s: "%s"' % ( error_prefix, module_path, e) six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg), sys.exc_info()[2]) try: attr = getattr(module, class_name) except AttributeError: Loading tests/utils_tests/module_loading.py +10 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,16 @@ class ModuleImportTestCase(unittest.TestCase): import_by_path('unexistent.module.path', error_prefix="Foo") self.assertTrue(str(cm.exception).startswith('Foo')) def test_import_error_traceback(self): """Test preserving the original traceback on an ImportError.""" try: import_by_path('test_module.bad_module.content') except ImproperlyConfigured: traceback = sys.exc_info()[2] self.assertIsNotNone(traceback.tb_next.tb_next, 'Should have more than the calling frame in the traceback.') class ProxyFinder(object): def __init__(self): Loading Loading
django/utils/module_loading.py +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import os import sys from django.core.exceptions import ImproperlyConfigured from django.utils import six from django.utils.importlib import import_module Loading @@ -19,8 +20,10 @@ def import_by_path(dotted_path, error_prefix=''): try: module = import_module(module_path) except ImportError as e: raise ImproperlyConfigured('%sError importing module %s: "%s"' % ( error_prefix, module_path, e)) msg = '%sError importing module %s: "%s"' % ( error_prefix, module_path, e) six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg), sys.exc_info()[2]) try: attr = getattr(module, class_name) except AttributeError: Loading
tests/utils_tests/module_loading.py +10 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,16 @@ class ModuleImportTestCase(unittest.TestCase): import_by_path('unexistent.module.path', error_prefix="Foo") self.assertTrue(str(cm.exception).startswith('Foo')) def test_import_error_traceback(self): """Test preserving the original traceback on an ImportError.""" try: import_by_path('test_module.bad_module.content') except ImproperlyConfigured: traceback = sys.exc_info()[2] self.assertIsNotNone(traceback.tb_next.tb_next, 'Should have more than the calling frame in the traceback.') class ProxyFinder(object): def __init__(self): Loading