From 17173f65d3003e6ba9622a614a196178e8dd3136 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 19 Sep 2020 17:38:25 +0200 Subject: [PATCH] Also added basic check of exceptinHandler --- nw/error.py | 7 +++++-- tests/test_error.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nw/error.py b/nw/error.py index d7e191bb..e1283fbd 100644 --- a/nw/error.py +++ b/nw/error.py @@ -135,7 +135,7 @@ class NWErrorMessage(QDialog): # END Class NWErrorMessage -def exceptionHandler(exType, exValue, exTrace): +def exceptionHandler(exType, exValue, exTrace, testMode=False): """Function to catch unhandled global exceptions. """ import nw @@ -173,7 +173,10 @@ def exceptionHandler(exType, exValue, exTrace): logger.critical("Could not close the project before exiting") logger.critical(str(e)) - qApp.exit(1) + if testMode: + return errMsg.msgBody.toPlainText() + else: + qApp.exit(1) except Exception as e: logger.critical(str(e)) diff --git a/tests/test_error.py b/tests/test_error.py index 4b0172a7..25920917 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -8,7 +8,7 @@ import pytest from PyQt5.QtWidgets import qApp -from nw.error import NWErrorMessage +from nw.error import NWErrorMessage, exceptionHandler @pytest.mark.error def testErrorDialog(qtbot, nwFuncTemp, nwTemp): @@ -35,6 +35,11 @@ def testErrorDialog(qtbot, nwFuncTemp, nwTemp): nwErr._doClose() nwErr.close() + theMessage = exceptionHandler(Exception, "Second Error", sys.last_traceback, testMode=True) + assert theMessage + assert "Second Error" in theMessage + assert "Exception" in theMessage + nwGUI.closeMain() # qtbot.stopForInteraction()