Repository: nose-devs/nose2

Issue:
Loader errors throw away tracebacks and exception detail
For instance if a generator test throws an AttributeError, the details of the attribute error are lost and the user only sees "AttributeError" -- not very helpful.

Discussion:
landscape-bot: [![Code Health](https://landscape.io/badge/175759/landscape.svg?style=flat)](https://landscape.io/diff/163690)
Repository health decreased by 0.00% when pulling **[28cda3a](https://github.com/dlax/nose2/commit/28cda3abf4d51b58fd686b0b6c0ff5c46c38f51b) on dlax:generator-exception** into **[bf99453](https://github.com/nose-devs/nose2/commit/bf9945309d5118ad4723619452c486593964d1b8) on nose-devs:master**.

 * [1 new problem was found](https://landscape.io/diff/163690) (including 0 errors and 1 code smell).
 * [1 problem was fixed](https://landscape.io/diff/163690/fixed) (including 0 errors and 1 code smell).
coveralls: 
[![Coverage Status](https://coveralls.io/builds/2664738/badge)](https://coveralls.io/builds/2664738)

Coverage decreased (-0.06%) to 84.25% when pulling **28cda3abf4d51b58fd686b0b6c0ff5c46c38f51b on dlax:generator-exception** into **bf9945309d5118ad4723619452c486593964d1b8 on nose-devs:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2664738/badge)](https://coveralls.io/builds/2664738)

Coverage decreased (-0.06%) to 84.25% when pulling **28cda3abf4d51b58fd686b0b6c0ff5c46c38f51b on dlax:generator-exception** into **bf9945309d5118ad4723619452c486593964d1b8 on nose-devs:master**.

landscape-bot: [![Code Health](https://landscape.io/badge/175789/landscape.svg?style=flat)](https://landscape.io/diff/163709)
Repository health increased by 0.07% when pulling **[ce05d05](https://github.com/dlax/nose2/commit/ce05d05f4ed1d9bb60cade4ccdb031637385585b) on dlax:generator-exception** into **[bf99453](https://github.com/nose-devs/nose2/commit/bf9945309d5118ad4723619452c486593964d1b8) on nose-devs:master**.

 * No new problems were introduced.
 * [1 problem was fixed](https://landscape.io/diff/163709/fixed) (including 0 errors and 1 code smell).
coveralls: 
[![Coverage Status](https://coveralls.io/builds/2664909/badge)](https://coveralls.io/builds/2664909)

Coverage increased (+0.02%) to 84.32% when pulling **ce05d05f4ed1d9bb60cade4ccdb031637385585b on dlax:generator-exception** into **bf9945309d5118ad4723619452c486593964d1b8 on nose-devs:master**.

dlax: Hmm, this does not actually fixes #48 completly since the exception context is not forwarded down to the test failure. Will work further on this...
dlax: Pushed a new version.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/2668668/badge)](https://coveralls.io/builds/2668668)

Coverage decreased (-2.57%) to 81.73% when pulling **778265de7a289dda9ab9755ba2c08c89642b80ac on dlax:generator-exception** into **bf9945309d5118ad4723619452c486593964d1b8 on nose-devs:master**.

landscape-bot: [![Code Health](https://landscape.io/badge/176074/landscape.svg?style=flat)](https://landscape.io/diff/164010)
Code quality remained the same when pulling **[778265d](https://github.com/dlax/nose2/commit/778265de7a289dda9ab9755ba2c08c89642b80ac) on dlax:generator-exception** into **[bf99453](https://github.com/nose-devs/nose2/commit/bf9945309d5118ad4723619452c486593964d1b8) on nose-devs:master**.

Patch:
diff --git a/nose2/loader.py b/nose2/loader.py
index 2778280..394899f 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 @@ class PluggableTestLoader(object):
 
     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),))


Test patch:
diff --git a/nose2/tests/unit/test_loader.py b/nose2/tests/unit/test_loader.py
index 24114e5..8dc152c 100644
--- a/nose2/tests/unit/test_loader.py
+++ b/nose2/tests/unit/test_loader.py
@@ -8,6 +8,21 @@ class TestPluggableTestLoader(TestCase):
         self.session = session.Session()
         self.loader = loader.PluggableTestLoader(self.session)
 
+    def test_failed_load_tests_exception(self):
+        suite = self.loader.failedLoadTests('test', RuntimeError('err'))
+        tc = suite._tests[0]
+        with self.assertRaises(RuntimeError) as cm:
+            tc.test()
+        self.assertEqual(cm.exception.args, ('err', ))
+
+    def test_failed_load_tests_exc_info(self):
+        suite = self.loader.failedLoadTests(
+            'test', (RuntimeError, RuntimeError('err'), None))
+        tc = suite._tests[0]
+        with self.assertRaises(RuntimeError) as cm:
+            tc.test()
+        self.assertEqual(cm.exception.args, ('err', ))
+
     def test_load_from_module_calls_hook(self):
         self.session.hooks.register('loadTestsFromModule', FakePlugin())
         evt = events.LoadFromModuleEvent(self.loader, 'some_module')