[1.8.x] Made the autoreloader survive all exceptions.
Refs #24704.
Backport of b79fc11d73
from master
This commit is contained in:
parent
cc14d51ee8
commit
2b08b36488
|
@ -227,8 +227,7 @@ def check_errors(fn):
|
|||
global _exception
|
||||
try:
|
||||
fn(*args, **kwargs)
|
||||
except (ImportError, IndentationError, NameError, SyntaxError,
|
||||
TypeError, AttributeError):
|
||||
except Exception:
|
||||
_exception = sys.exc_info()
|
||||
|
||||
et, ev, tb = _exception
|
||||
|
|
|
@ -169,3 +169,19 @@ class TestFilenameGenerator(TestCase):
|
|||
with self.assertRaises(SyntaxError):
|
||||
autoreload.check_errors(import_module)('test_syntax_error')
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue