def test_excepthook(): """ Test that custom excepthook logs error and calls sys.exit. """ ex = Exception('BANG') exc_args = (type(ex), ex, ex.__traceback__) with mock.patch('mu.app.logging.error') as error, \ mock.patch('mu.app.sys.exit') as exit: excepthook(*exc_args) error.assert_called_once_with('Unrecoverable error', exc_info=exc_args) exit.assert_called_once_with(1)
def test_excepthook(): """ Test that custom excepthook logs error and calls sys.exit. """ ex = Exception("BANG") exc_args = (type(ex), ex, ex.__traceback__) with mock.patch("mu.app.logging.error") as error, mock.patch( "mu.app.sys.exit") as exit, mock.patch( "mu.app.webbrowser") as browser: excepthook(*exc_args) error.assert_called_once_with("Unrecoverable error", exc_info=exc_args) exit.assert_called_once_with(1) assert browser.open.call_count == 1
def test_excepthook_alamo(): """ If the crash reporting code itself encounters an error, then ensure this is logged before exiting. """ ex = Exception("BANG") exc_args = (type(ex), ex, ex.__traceback__) mock_browser = mock.MagicMock() mock_browser.open.side_effect = RuntimeError("BROWSER BANG") with mock.patch("mu.app.logging.error") as error, mock.patch( "mu.app.sys.exit") as exit, mock.patch("mu.app.webbrowser", mock_browser): excepthook(*exc_args) assert error.call_count == 2 exit.assert_called_once_with(1)