From 19571d34374026649783ff57289dd4a9c6bdf028 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 27 May 2015 21:52:45 +0200 Subject: [PATCH] Restore exception context when passed in loader's _makeFailedTest method Loader's `_makeFailedTest` now handles both the case where `exception` is an Exception instance and the case where `exception` is an exception information tuple (as given by `sys.exc_info()`). Rely on six.reraise to handle the latter case. Closes #48. --- nose2/loader.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nose2/loader.py b/nose2/loader.py index 27782805..394899fd 100644 --- a/nose2/loader.py +++ b/nose2/loader.py @@ -7,6 +7,8 @@ import logging import traceback +import six + from nose2 import events from nose2.compat import unittest @@ -114,7 +116,11 @@ def discover(self, start_dir=None, pattern=None): def _makeFailedTest(self, classname, methodname, exception): def testFailure(self): - raise exception + if isinstance(exception, Exception): + raise exception + else: + # exception tuple (type, value, traceback) + six.reraise(*exception) attrs = {methodname: testFailure} TestClass = type(classname, (unittest.TestCase,), attrs) return self.suiteClass((TestClass(methodname),))