Skip to content

Commit

Permalink
Merge pull request #7503 from kozlovsky/fix/raising_assertion_error_i…
Browse files Browse the repository at this point in the history
…n_test

Use TestError instead of AssertionError in test to avoid confusion
  • Loading branch information
kozlovsky authored Jun 27, 2023
2 parents 9d8bf67 + 179d5f7 commit 178f583
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/tribler/gui/tests/test_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,32 @@ def reported_error():
return ReportedError(type='Exception', text='text', event={})


class TestError(Exception):
pass


@patch('tribler.gui.error_handler.FeedbackDialog')
def test_gui_error_tribler_stopped(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler):
# test that while tribler_stopped is True FeedbackDialog is not called
error_handler._tribler_stopped = True
error_handler.gui_error(AssertionError, AssertionError("error text"), None)
error_handler.gui_error(TestError, TestError("error text"), None)
mocked_feedback_dialog.assert_not_called()


@patch('tribler.gui.error_handler.FeedbackDialog')
@patch.object(SentryReporter, 'global_strategy', create=True,
new=PropertyMock(return_value=SentryStrategy.SEND_SUPPRESSED))
def test_gui_error_suppressed(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler):
error_handler.gui_error(AssertionError, AssertionError('error_text'), None)
error_handler.gui_error(TestError, TestError('error_text'), None)
mocked_feedback_dialog.assert_not_called()
assert not error_handler._handled_exceptions


@patch('tribler.gui.error_handler.FeedbackDialog')
def test_gui_info_type_in_handled_exceptions(mocked_feedback_dialog: MagicMock, error_handler: ErrorHandler):
# test that if exception type in _handled_exceptions then FeedbackDialog is not called
error_handler._handled_exceptions = {AssertionError}
error_handler.gui_error(AssertionError, AssertionError("error text"), None)
error_handler._handled_exceptions = {TestError}
error_handler.gui_error(TestError, TestError("error text"), None)
mocked_feedback_dialog.assert_not_called()
assert len(error_handler._handled_exceptions) == 1

Expand Down

0 comments on commit 178f583

Please sign in to comment.