This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 11:00 UTC+2 (a few minutes of down time)

Commit 4b37e077 authored by Yuya Nishihara's avatar Yuya Nishihara

tests: catch exception raised inside Qt event loop to report as error

Without the custom sys.excepthook, nose cannot catch exception raised

branch : stable
parent 50ce9d5666f0
"""Nose plugin to capture unhandled exception"""
import sys
from nose import plugins
class CaptureExcPlugin(plugins.Plugin):
"""Capture unhandled exception (probably raised inside event loop)"""
enabled = False
name = 'capture-exc'
def options(self, parser, env):
parser.add_option('--no-capture-exc', dest='capture_exc',
action='store_false', default=True,
help='Catch unhandled exception to report as error')
def configure(self, options, conf):
self.enabled = options.capture_exc
def prepareTestResult(self, result):
# dirty hack to access result.addError()
self._result = result
def startTest(self, test):
self._origexcepthook = sys.excepthook
sys.excepthook = self._excepthook
self._excepts = []
def stopTest(self, test):
sys.excepthook = self._origexcepthook
del self._origexcepthook
if self._excepts:
# BUG: because the corresponding addSuccess/Failure/Error for the
# given test is already called, this increases the test counts.
self._result.addError(test, self._excepts.pop(0))
def _excepthook(self, type, value, traceback):
self._excepts.append((type, value, traceback))
......@@ -14,7 +14,8 @@ For details, please see:
import os, sys
import nose
import nosehgenv
import nosecaptureexc, nosehgenv
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment