Ticket #30516: 30516.diff

File 30516.diff, 1.1 KB (added by Mariusz Felisiak, 5 years ago)

Regression test.

  • tests/utils_tests/test_autoreload.py

    diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
    index 42bcd0a50b..42afd8091f 100644
    a b class TestRaiseLastException(SimpleTestCase):  
    291291            with self.assertRaisesMessage(MyException, 'Test Message'):
    292292                autoreload.raise_last_exception()
    293293
     294    def test_raises_custom_exception(self):
     295        class MyException(Exception):
     296            def __init__(self, msg, extra_context):
     297                super().__init__(msg)
     298                self.extra_context = extra_context
     299
     300        # Create an exception
     301        try:
     302            raise MyException('Test Message', 'extra context')
     303        except MyException:
     304            exc_info = sys.exc_info()
     305
     306        with mock.patch('django.utils.autoreload._exception', exc_info):
     307            with self.assertRaisesMessage(MyException, 'Test Message'):
     308                autoreload.raise_last_exception()
     309
    294310
    295311class RestartWithReloaderTests(SimpleTestCase):
    296312    executable = '/usr/bin/python'
Back to Top