summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJames Westby <james.westby@linaro.org>2011-11-01 11:59:58 -0400
committerJames Westby <james.westby@linaro.org>2011-11-01 11:59:58 -0400
commit5c3f13ee9f2d195b605a1b3522fb00e8d5e79786 (patch)
tree06a0cbade27dfe95d42101b31ba613e03e994f20 /python
parent81aa7596833daa779ddfb3eb352e9b8c64e947c6 (diff)
downloadsubunit-git-5c3f13ee9f2d195b605a1b3522fb00e8d5e79786.tar.gz
Have the output of subunit.run include timing information.
Diffstat (limited to 'python')
-rwxr-xr-xpython/subunit/run.py2
-rw-r--r--python/subunit/tests/__init__.py2
-rw-r--r--python/subunit/tests/test_run.py53
3 files changed, 57 insertions, 0 deletions
diff --git a/python/subunit/run.py b/python/subunit/run.py
index 51d6837..ca5fe5c 100755
--- a/python/subunit/run.py
+++ b/python/subunit/run.py
@@ -23,6 +23,7 @@
import sys
from subunit import TestProtocolClient, get_default_formatter
+from subunit.test_results import AutoTimingTestResultDecorator
from testtools.run import (
BUFFEROUTPUT,
CATCHBREAK,
@@ -39,6 +40,7 @@ class SubunitTestRunner(object):
def run(self, test):
"Run the given test case or test suite."
result = TestProtocolClient(self.stream)
+ result = AutoTimingTestResultDecorator(result)
test(result)
return result
diff --git a/python/subunit/tests/__init__.py b/python/subunit/tests/__init__.py
index a78cec8..e0e1eb1 100644
--- a/python/subunit/tests/__init__.py
+++ b/python/subunit/tests/__init__.py
@@ -19,6 +19,7 @@ from subunit.tests import (
test_chunked,
test_details,
test_progress_model,
+ test_run,
test_subunit_filter,
test_subunit_stats,
test_subunit_tags,
@@ -38,4 +39,5 @@ def test_suite():
result.addTest(test_subunit_filter.test_suite())
result.addTest(test_subunit_tags.test_suite())
result.addTest(test_subunit_stats.test_suite())
+ result.addTest(test_run.test_suite())
return result
diff --git a/python/subunit/tests/test_run.py b/python/subunit/tests/test_run.py
new file mode 100644
index 0000000..e695703
--- /dev/null
+++ b/python/subunit/tests/test_run.py
@@ -0,0 +1,53 @@
+#
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net>
+# Copyright (C) 2011 Martin Pool <mbp@sourcefrog.net>
+#
+# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
+# license at the users choice. A copy of both licenses are available in the
+# project source as Apache-2.0 and BSD. You may not use this file except in
+# compliance with one of these two licences.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# license you chose for the specific language governing permissions and
+# limitations under that license.
+#
+
+from cStringIO import StringIO
+import unittest
+
+from testtools import PlaceHolder
+
+import subunit
+from subunit.run import SubunitTestRunner
+
+
+def test_suite():
+ loader = subunit.tests.TestUtil.TestLoader()
+ result = loader.loadTestsFromName(__name__)
+ return result
+
+
+class TimeCollectingTestResult(unittest.TestResult):
+
+ def __init__(self, *args, **kwargs):
+ super(TimeCollectingTestResult, self).__init__(*args, **kwargs)
+ self.time_called = []
+
+ def time(self, a_time):
+ self.time_called.append(a_time)
+
+
+class TestSubunitTestRunner(unittest.TestCase):
+
+ def test_includes_timing_output(self):
+ io = StringIO()
+ runner = SubunitTestRunner(stream=io)
+ test = PlaceHolder('name')
+ runner.run(test)
+ client = TimeCollectingTestResult()
+ io.seek(0)
+ subunit.TestProtocolServer(client).readFrom(io)
+ self.assertTrue(len(client.time_called) > 0)