Made the autoreloader survive all exceptions.

Refs #24704.
This commit is contained in:
Aymeric Augustin 2015-08-29 13:26:00 +02:00
parent fe6ddb837d
commit b79fc11d73
2 changed files with 17 additions and 2 deletions

View File

@ -224,8 +224,7 @@ def check_errors(fn):
global _exception global _exception
try: try:
fn(*args, **kwargs) fn(*args, **kwargs)
except (ImportError, IndentationError, NameError, SyntaxError, except Exception:
TypeError, AttributeError):
_exception = sys.exc_info() _exception = sys.exc_info()
et, ev, tb = _exception et, ev, tb = _exception

View File

@ -169,3 +169,19 @@ class TestFilenameGenerator(SimpleTestCase):
with self.assertRaises(SyntaxError): with self.assertRaises(SyntaxError):
autoreload.check_errors(import_module)('test_syntax_error') autoreload.check_errors(import_module)('test_syntax_error')
self.assertFileFoundOnlyNew(filename) self.assertFileFoundOnlyNew(filename)
def test_check_errors_catches_all_exceptions(self):
"""
Since Python may raise arbitrary exceptions when importing code,
check_errors() must catch Exception, not just some subclasses.
"""
dirname = tempfile.mkdtemp()
filename = os.path.join(dirname, 'test_exception.py')
self.addCleanup(shutil.rmtree, dirname)
with open(filename, 'w') as f:
f.write("raise Exception")
with extend_sys_path(dirname):
with self.assertRaises(Exception):
autoreload.check_errors(import_module)('test_exception')
self.assertFileFound(filename)