diff options
| author | Tom Forbes <tom@tomforb.es> | 2019-05-28 19:06:39 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-29 08:30:22 +0200 |
| commit | ace0bec804d0bd74e1ecddbe3ea9a8b5b5d0a718 (patch) | |
| tree | 613059486a39c15f6f5cfea671abe5797338d0a4 /tests | |
| parent | 0f0d1cd7722238158011c7717d410fae37513ceb (diff) | |
[2.2.x] Fixed #30516 -- Fixed crash of autoreloader when re-raising exceptions with custom signature.
Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.
Backport of 0344565179527d80990e2247e3be7c04aa8c43c8 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/utils_tests/test_autoreload.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 9253482e7b..82f7287fa8 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -293,6 +293,36 @@ class TestRaiseLastException(SimpleTestCase): with self.assertRaisesMessage(MyException, 'Test Message'): autoreload.raise_last_exception() + def test_raises_custom_exception(self): + class MyException(Exception): + def __init__(self, msg, extra_context): + super().__init__(msg) + self.extra_context = extra_context + # Create an exception. + try: + raise MyException('Test Message', 'extra context') + except MyException: + exc_info = sys.exc_info() + + with mock.patch('django.utils.autoreload._exception', exc_info): + with self.assertRaisesMessage(MyException, 'Test Message'): + autoreload.raise_last_exception() + + def test_raises_exception_with_context(self): + try: + raise Exception(2) + except Exception as e: + try: + raise Exception(1) from e + except Exception: + exc_info = sys.exc_info() + + with mock.patch('django.utils.autoreload._exception', exc_info): + with self.assertRaises(Exception) as cm: + autoreload.raise_last_exception() + self.assertEqual(cm.exception.args[0], 1) + self.assertEqual(cm.exception.__cause__.args[0], 2) + class RestartWithReloaderTests(SimpleTestCase): executable = '/usr/bin/python' |
