summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2014-02-11 13:38:15 +1300
committerRobert Collins <robertc@robertcollins.net>2014-02-11 13:38:15 +1300
commitdbc0c6cbbd7f6cc6a3b2bb617525e6f16b817359 (patch)
tree850e377ddabc39d7ca313ddaf462dbe9f5c1dd4f
parent705741ab624c2570f1f30b99808809f239f60859 (diff)
downloadtestrepository-dbc0c6cbbd7f6cc6a3b2bb617525e6f16b817359.tar.gz
* When list-tests encounters an error, a much clearer response will
now be shown. (Robert Collins, #1271133)
-rw-r--r--NEWS3
-rw-r--r--testrepository/results.py26
-rw-r--r--testrepository/testcommand.py13
3 files changed, 40 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index e17b622..17b92aa 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,9 @@ CHANGES
* ``run`` was outputting bad MIME types - test/plain, not text/plain.
(Robert Collins)
+* When list-tests encounters an error, a much clearer response will
+ now be shown. (Robert Collins, #1271133)
+
0.0.18
++++++
diff --git a/testrepository/results.py b/testrepository/results.py
index ed01856..2babcb0 100644
--- a/testrepository/results.py
+++ b/testrepository/results.py
@@ -13,7 +13,11 @@
# limitations under that license.
-from testtools import StreamSummary
+import subunit
+from testtools import (
+ StreamSummary,
+ StreamResult,
+ )
from testrepository.utils import timedelta_to_seconds
@@ -47,3 +51,23 @@ class SummarizingResult(StreamSummary):
if None in (self._last_time, self._first_time):
return None
return timedelta_to_seconds(self._last_time - self._first_time)
+
+
+#XXX: Should be in testtools.
+class CatFiles(StreamResult):
+ """Cat file attachments received to a stream."""
+
+ def __init__(self, byte_stream):
+ self.stream = subunit.make_stream_binary(byte_stream)
+ self.last_file = None
+
+ def status(self, test_id=None, test_status=None, test_tags=None,
+ runnable=True, file_name=None, file_bytes=None, eof=False,
+ mime_type=None, route_code=None, timestamp=None):
+ if file_name is None:
+ return
+ if self.last_file != file_name:
+ self.stream.write(("--- %s ---\n" % file_name).encode('utf8'))
+ self.last_file = file_name
+ self.stream.write(file_bytes)
+ self.stream.flush()
diff --git a/testrepository/testcommand.py b/testrepository/testcommand.py
index 267f4ef..f2d51ef 100644
--- a/testrepository/testcommand.py
+++ b/testrepository/testcommand.py
@@ -14,10 +14,14 @@
"""The test command that test repository knows how to run."""
-from extras import try_imports
+from extras import (
+ try_import,
+ try_imports,
+ )
from collections import defaultdict
ConfigParser = try_imports(['ConfigParser', 'configparser'])
+import io
import itertools
import operator
import os.path
@@ -29,7 +33,9 @@ import multiprocessing
from textwrap import dedent
from fixtures import Fixture
+v2 = try_import('subunit.v2')
+from testrepository import results
from testrepository.testlist import (
parse_enumeration,
write_list,
@@ -294,6 +300,11 @@ class TestListingFixture(Fixture):
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
out, err = run_proc.communicate()
if run_proc.returncode != 0:
+ if v2 is not None:
+ new_out = io.BytesIO()
+ v2.ByteStreamToStreamResult(io.BytesIO(out), 'stdout').run(
+ results.CatFiles(new_out))
+ out = new_out.getvalue()
raise ValueError(
"Non-zero exit code (%d) from test listing."
" stdout=%r, stderr=%r" % (run_proc.returncode, out, err))