better error handling for errors during conf import
This commit is contained in:
@@ -110,17 +110,10 @@ def import_module(conf):
|
||||
try:
|
||||
module = __import__(name, fromlist=fromlist)
|
||||
conf_mod = getattr(module, parts[-1])
|
||||
except ImportError, e:
|
||||
raise ImportError('No module named %s' % conf)
|
||||
except AttributeError, e:
|
||||
raise ImportError('No module named %s' % conf)
|
||||
else:
|
||||
name = conf
|
||||
|
||||
try:
|
||||
conf_mod = __import__(name)
|
||||
except ImportError, e:
|
||||
raise ImportError('No module named %s' % conf)
|
||||
conf_mod = __import__(conf)
|
||||
|
||||
return conf_mod
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ class TestConf(TestCase):
|
||||
self.assertRaises(ImportError, conf.update_with_module, 'doesnotexist')
|
||||
self.assertRaises(ImportError, conf.update_with_module, 'bad.doesnotexists')
|
||||
self.assertRaises(ImportError, conf.update_with_module, 'bad.bad.doesnotexist')
|
||||
self.assertRaises(SyntaxError, conf.update_with_module, 'bad.syntaxerror')
|
||||
self.assertRaises(ImportError, conf.update_with_module, 'bad.importerror')
|
||||
|
||||
def test_config_set_from_file(self):
|
||||
path = os.path.join(os.path.dirname(__file__), 'test_config', 'empty.py')
|
||||
|
||||
1
tests/test_config/bad/importerror.py
Normal file
1
tests/test_config/bad/importerror.py
Normal file
@@ -0,0 +1 @@
|
||||
import pecan.thismoduledoesnotexist
|
||||
3
tests/test_config/bad/syntaxerror.py
Normal file
3
tests/test_config/bad/syntaxerror.py
Normal file
@@ -0,0 +1,3 @@
|
||||
if false
|
||||
var = 3
|
||||
|
||||
Reference in New Issue
Block a user