Fixed isolation of utils_tests.test_autoreload tests.

This commit is contained in:
Mariusz Felisiak 2021-01-20 09:53:34 +01:00 committed by GitHub
parent dc2ddfe91a
commit cfddca543a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -86,8 +86,11 @@ class TestIterModulesAndFiles(SimpleTestCase):
filename.write_text("Ceci n'est pas du Python.")
with extend_sys_path(str(filename.parent)):
with self.assertRaises(SyntaxError):
autoreload.check_errors(import_module)('test_syntax_error')
try:
with self.assertRaises(SyntaxError):
autoreload.check_errors(import_module)('test_syntax_error')
finally:
autoreload._exception = None
self.assertFileFound(filename)
def test_check_errors_catches_all_exceptions(self):
@ -370,8 +373,11 @@ class TestCheckErrors(SimpleTestCase):
fake_method = mock.MagicMock(side_effect=RuntimeError())
wrapped = autoreload.check_errors(fake_method)
with mock.patch.object(autoreload, '_error_files') as mocked_error_files:
with self.assertRaises(RuntimeError):
wrapped()
try:
with self.assertRaises(RuntimeError):
wrapped()
finally:
autoreload._exception = None
self.assertEqual(mocked_error_files.append.call_count, 1)