Rev 4064: (robertc) Move skipping-test detection to TestCase from TestResult. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sun Mar 1 12:19:01 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4064
revision-id: pqm at pqm.ubuntu.com-20090301121857-3lxdqurjbln7ybd2
parent: pqm at pqm.ubuntu.com-20090227165204-wtg2koex221f2g8b
parent: robertc at robertcollins.net-20090301111114-jupiev5u7eog3b52
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2009-03-01 12:18:57 +0000
message:
(robertc) Move skipping-test detection to TestCase from TestResult.
(Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
------------------------------------------------------------
revno: 4063.1.3
revision-id: robertc at robertcollins.net-20090301111114-jupiev5u7eog3b52
parent: robertc at robertcollins.net-20090301095707-w52moizbku399auj
committer: Robert Collins <robertc at robertcollins.net>
branch nick: integration
timestamp: Sun 2009-03-01 22:11:14 +1100
message:
Python2.4 compatibility.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
------------------------------------------------------------
revno: 4063.1.2
revision-id: robertc at robertcollins.net-20090301095707-w52moizbku399auj
parent: robertc at robertcollins.net-20090301025751-v3ihbtlpaqiokzv9
committer: Robert Collins <robertc at robertcollins.net>
branch nick: test-skipped
timestamp: Sun 2009-03-01 20:57:07 +1100
message:
Remove duplicate except block.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
------------------------------------------------------------
revno: 4063.1.1
revision-id: robertc at robertcollins.net-20090301025751-v3ihbtlpaqiokzv9
parent: pqm at pqm.ubuntu.com-20090227165204-wtg2koex221f2g8b
committer: Robert Collins <robertc at robertcollins.net>
branch nick: test-skipped
timestamp: Sun 2009-03-01 13:57:51 +1100
message:
Move skipped test detection to TestCase, and make reporting use an addSkip method as per testtools.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS 2009-02-27 08:29:09 +0000
+++ b/NEWS 2009-03-01 02:57:51 +0000
@@ -166,6 +166,13 @@
to aid branch types that are not bzr branch objects (like
RemoteBranch). (Robert Collins, Andrew Bennetts)
+ * ``TestSkipped`` is now detected by TestCase and passed to the
+ ``TestResult`` by calling ``addSkip``. For older TestResult objects,
+ where ``addSkip`` is not available, ``addError`` is still called.
+ This permits test filtering in subunit to strip out skipped tests
+ resulting in a faster fix-shrink-list-run cycle. This is compatible
+ with the testtools protocol for skips. (Robert Collins)
+
* The ``_index`` of ``KnitVersionedFiles`` now supports the ability
to scan an underlying index that is going to be incorporated into
the ``KnitVersionedFiles`` object, to determine if it has missing
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-02-25 23:52:42 +0000
+++ b/bzrlib/tests/__init__.py 2009-03-01 11:11:14 +0000
@@ -216,8 +216,8 @@
fails with an unexpected error.
"""
self._testConcluded(test)
- if isinstance(err[1], TestSkipped):
- return self._addSkipped(test, err)
+ if isinstance(err[1], TestNotApplicable):
+ return self._addNotApplicable(test, err)
elif isinstance(err[1], UnavailableFeature):
return self.addNotSupported(test, err[1].args[0])
else:
@@ -286,19 +286,21 @@
self.unsupported[str(feature)] += 1
self.report_unsupported(test, feature)
- def _addSkipped(self, test, skip_excinfo):
+ def addSkip(self, test, reason):
+ """A test has not run for 'reason'."""
+ self.skip_count += 1
+ self.report_skip(test, reason)
+
+ def _addNotApplicable(self, test, skip_excinfo):
if isinstance(skip_excinfo[1], TestNotApplicable):
self.not_applicable_count += 1
self.report_not_applicable(test, skip_excinfo)
- else:
- self.skip_count += 1
- self.report_skip(test, skip_excinfo)
try:
test.tearDown()
except KeyboardInterrupt:
raise
except:
- self.addError(test, test._exc_info())
+ self.addError(test, test.exc_info())
else:
# seems best to treat this as success from point-of-view of unittest
# -- it actually does nothing so it barely matters :)
@@ -416,7 +418,7 @@
self.pb.note('XFAIL: %s\n%s\n',
self._test_description(test), err[1])
- def report_skip(self, test, skip_excinfo):
+ def report_skip(self, test, reason):
pass
def report_not_applicable(self, test, skip_excinfo):
@@ -485,10 +487,9 @@
# used to show the output in PQM.
self.stream.flush()
- def report_skip(self, test, skip_excinfo):
+ def report_skip(self, test, reason):
self.stream.writeln(' SKIP %s\n%s'
- % (self._testTimeString(test),
- self._error_summary(skip_excinfo)))
+ % (self._testTimeString(test), reason))
def report_not_applicable(self, test, skip_excinfo):
self.stream.writeln(' N/A %s\n%s'
@@ -775,6 +776,13 @@
TestCase._active_threads = threading.activeCount()
self.addCleanup(self._check_leaked_threads)
+ def exc_info(self):
+ absent_attr = object()
+ exc_info = getattr(self, '_exc_info', absent_attr)
+ if exc_info is absent_attr:
+ exc_info = getattr(self, '_TestCase__exc_info')
+ return exc_info()
+
def _check_leaked_threads(self):
active = threading.activeCount()
leaked_threads = active - TestCase._active_threads
@@ -1282,6 +1290,13 @@
"""This test has failed for some known reason."""
raise KnownFailure(reason)
+ def _do_skip(self, result, reason):
+ addSkip = getattr(result, 'addSkip', None)
+ if not callable(addSkip):
+ result.addError(self, self.exc_info())
+ else:
+ addSkip(self, reason)
+
def run(self, result=None):
if result is None: result = self.defaultTestResult()
for feature in getattr(self, '_test_needs_features', []):
@@ -1294,7 +1309,61 @@
result.stopTest(self)
return
try:
- return unittest.TestCase.run(self, result)
+ try:
+ result.startTest(self)
+ absent_attr = object()
+ # Python 2.5
+ method_name = getattr(self, '_testMethodName', absent_attr)
+ if method_name is absent_attr:
+ # Python 2.4
+ method_name = getattr(self, '_TestCase__testMethodName')
+ testMethod = getattr(self, method_name)
+ try:
+ try:
+ self.setUp()
+ except KeyboardInterrupt:
+ raise
+ except TestSkipped, e:
+ self._do_skip(result, e.args[0])
+ self.tearDown()
+ return
+ except:
+ result.addError(self, self.exc_info())
+ return
+
+ ok = False
+ try:
+ testMethod()
+ ok = True
+ except self.failureException:
+ result.addFailure(self, self.exc_info())
+ except TestSkipped, e:
+ if not e.args:
+ reason = "No reason given."
+ else:
+ reason = e.args[0]
+ self._do_skip(result, reason)
+ except KeyboardInterrupt:
+ raise
+ except:
+ result.addError(self, self.exc_info())
+
+ try:
+ self.tearDown()
+ except KeyboardInterrupt:
+ raise
+ except:
+ result.addError(self, self.exc_info())
+ ok = False
+ if ok: result.addSuccess(self)
+ finally:
+ result.stopTest(self)
+ return
+ except TestNotApplicable:
+ # Not moved from the result [yet].
+ raise
+ except KeyboardInterrupt:
+ raise
finally:
saved_attrs = {}
absent_attr = object()
@@ -1306,6 +1375,7 @@
def tearDown(self):
self._runCleanups()
+ self._log_contents = ''
unittest.TestCase.tearDown(self)
def time(self, callable, *args, **kwargs):
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2009-02-23 15:29:35 +0000
+++ b/bzrlib/tests/test_selftest.py 2009-03-01 02:57:51 +0000
@@ -1108,11 +1108,11 @@
# run a test that is skipped, and check the suite as a whole still
# succeeds.
# skipping_test must be hidden in here so it's not run as a real test
- def skipping_test():
- raise TestSkipped('test intentionally skipped')
-
+ class SkippingTest(TestCase):
+ def skipping_test(self):
+ raise TestSkipped('test intentionally skipped')
runner = TextTestRunner(stream=self._log_file)
- test = unittest.FunctionTestCase(skipping_test)
+ test = SkippingTest("skipping_test")
result = self.run_test_runner(runner, test)
self.assertTrue(result.wasSuccessful())
More information about the bazaar-commits
mailing list