Rev 4574: Don't call countTestCases from TextTestRunner.run, rather let tests decide if they want to be counted. in http://bazaar.launchpad.net/~lifeless/bzr/test_progress
Robert Collins
robertc at robertcollins.net
Tue Jul 28 22:50:10 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/test_progress
------------------------------------------------------------
revno: 4574
revision-id: robertc at robertcollins.net-20090728214959-z0z01q2m47phmkcw
parent: pqm at pqm.ubuntu.com-20090727093330-882xn6s1tt1zbnw6
committer: Robert Collins <robertc at robertcollins.net>
branch nick: test_progress
timestamp: Wed 2009-07-29 07:49:59 +1000
message:
Don't call countTestCases from TextTestRunner.run, rather let tests decide if they want to be counted.
=== modified file 'NEWS'
--- a/NEWS 2009-07-27 05:24:02 +0000
+++ b/NEWS 2009-07-28 21:49:59 +0000
@@ -138,6 +138,13 @@
* --subunit support now adds timestamps if the subunit version supports
it. (Robert Collins)
+* The ``bzrlib.tests.TextTestRunner`` will no longer call
+ ``countTestsCases`` on the test being run. Progress information is
+ instead handled by having the test passed in call ``result.progress``
+ before running its contents. This improves the behaviour when using
+ ``TextTestRunner`` with test suites that don't support
+ ``countTestsCases``. (Robert Collins)
+
bzr 1.17 "So late it's brunch" 2009-07-20
#########################################
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-07-23 04:46:26 +0000
+++ b/bzrlib/tests/__init__.py 2009-07-28 21:49:59 +0000
@@ -134,7 +134,6 @@
def __init__(self, stream, descriptions, verbosity,
bench_history=None,
- num_tests=None,
strict=False,
):
"""Construct new TestResult.
@@ -159,7 +158,7 @@
bench_history.write("--date %s %s\n" % (time.time(), revision_id))
self._bench_history = bench_history
self.ui = ui.ui_factory
- self.num_tests = num_tests
+ self.num_tests = 0
self.error_count = 0
self.failure_count = 0
self.known_failure_count = 0
@@ -359,6 +358,15 @@
self.stream.writeln(self.separator2)
self.stream.writeln("%s" % err)
+ def progress(self, offset, whence):
+ """The test is adjusting the count of tests to run."""
+ if whence == os.SEEK_SET:
+ self.num_tests = offset
+ elif whence == os.SEEK_CUR:
+ self.num_tests += offset
+ else:
+ raise errors.BzrError("Unknown whence %r" % whence)
+
def finished(self):
pass
@@ -379,12 +387,11 @@
def __init__(self, stream, descriptions, verbosity,
bench_history=None,
- num_tests=None,
pb=None,
strict=None,
):
ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
- bench_history, num_tests, strict)
+ bench_history, strict)
if pb is None:
self.pb = self.ui.nested_progress_bar()
self._supplied_pb = False
@@ -410,7 +417,7 @@
## a += ', %d skip' % self.skip_count
## if self.known_failure_count:
## a += '+%dX' % self.known_failure_count
- if self.num_tests is not None:
+ if self.num_tests:
a +='/%d' % self.num_tests
a += ' in '
runtime = time.time() - self._overall_start_time
@@ -566,7 +573,6 @@
self.descriptions,
self.verbosity,
bench_history=self._bench_history,
- num_tests=test.countTestCases(),
strict=self._strict,
)
result.stop_early = self.stop_on_failure
@@ -2752,6 +2758,8 @@
decorators.append(filter_tests(pattern))
if suite_decorators:
decorators.extend(suite_decorators)
+ # tell the result object how many tests will be running:
+ decorators.append(CountingDecorator)
for decorator in decorators:
suite = decorator(suite)
result = runner.run(suite)
@@ -2861,6 +2869,16 @@
return result
+class CountingDecorator(TestDecorator):
+ """A decorator which calls result.progress(self.countTestCases)."""
+
+ def run(self, result):
+ progress_method = getattr(result, 'progress', None)
+ if callable(progress_method):
+ progress_method(self.countTestCases(), os.SEEK_SET)
+ return super(CountingDecorator, self).run(result)
+
+
class ExcludeDecorator(TestDecorator):
"""A decorator which excludes test matching an exclude pattern."""
More information about the bazaar-commits
mailing list