Improve showing of import errors in the Python runner.
authorRobert Collins <robertc@robertcollins.net>
Tue, 18 Nov 2014 08:57:57 +0000 (21:57 +1300)
committerRobert Collins <robertc@robertcollins.net>
Tue, 18 Nov 2014 08:57:57 +0000 (21:57 +1300)
This depends on testtools 1.4.0 to get the improved behaviour.

NEWS
python/subunit/run.py
python/subunit/tests/test_run.py

diff --git a/NEWS b/NEWS
index 60028d9a1889b62b4a930bcb32e5a6b494620aef..ed281acd9c58300681dc436f8bfef7ea32919a20 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,12 @@ BUGFIXES
 * Tests have been fixed with testtools 1.2.0 and above.
   (Robert Collins)
 
+IMPROVEMENTS
+~~~~~~~~~~~~
+
+* With testtools 1.4.0 and above import errors are now
+  shown in detail by ``subunit.run``. (Robert Collins)
+
 0.0.21
 ------
 
index cf9cc01d068e95c34a5651bd478067bc29765842..5bf1db23d35ab62672cbff748587f861ab5392a5 100755 (executable)
@@ -70,9 +70,13 @@ class SubunitTestRunner(object):
             result.stopTestRun()
         return result
 
-    def list(self, test):
+    def list(self, test, loader=None):
         "List the test."
         result, errors = self._list(test)
+        if loader is not None:
+            # We were called with the updated API by testtools.run, so look for
+            # errors on the loader, not the test list result.
+            errors = loader.errors
         if errors:
             failed_descr = '\n'.join(errors).encode('utf8')
             result.status(file_name="import errors", runnable=False,
index de9b0942a0986b0e0f5892e217cdce62f45d55ec..3339a829b62d4090e1e149521d6e86a4655f83e4 100644 (file)
@@ -65,6 +65,18 @@ class TestSubunitTestRunner(TestCase):
         exc = self.assertRaises(SystemExit, runner.list, None)
         self.assertEqual((2,), exc.args)
 
+    def test_list_includes_loader_errors(self):
+        bytestream = io.BytesIO()
+        runner = SubunitTestRunner(stream=bytestream)
+        def list_test(test):
+            return [], []
+        class Loader(object):
+            errors = ['failed import']
+        loader = Loader()
+        self.patch(run, 'list_test', list_test)
+        exc = self.assertRaises(SystemExit, runner.list, None, loader=loader)
+        self.assertEqual((2,), exc.args)
+
     class FailingTest(TestCase):
         def test_fail(self):
             1/0