[MERGE] Allow plugins to select test runner class
Robert Collins
robertc at robertcollins.net
Thu Feb 12 05:04:26 GMT 2009
This is a minor refactoring of cmd_selftest to allow a plugin hooked
into the command to influence the test runner class.
The following code demonstrates a plugin to do this for subunit - 'bzr
selftest --subunit' will output a subunit test stream.
import sys
from bzrlib.commands import Command
from bzrlib.option import Option
def setup_subunit_option(cmd):
if cmd.name() == 'selftest':
def set_subunit_runner(option, name, new_value, parser):
# We're active: import dependencies and setup environment
from bzrlib.tests import TextTestRunner
from bzrlib import osutils
from subunit import TestProtocolClient
class SubUnitBzrRunner(TextTestRunner):
def run(self, test):
# undo bzrlib's claim for testing which looks like a test.
self.stream.write("success: %s\n" % (osutils.realpath(sys.argv[0]),))
result = TestProtocolClient(self.stream)
test.run(result)
return result
cmd.additional_selftest_args['runner_class'] = SubUnitBzrRunner
# Don't pass 'subunit' as an option down to cmd_selftest's run
# method.
del parser.values.__dict__['subunit']
# Don't alter class variables
cmd.takes_options = list(cmd.takes_options)
cmd.takes_options.append(
Option('subunit', help='Output test progress as a subunit stream.',
custom_callback=set_subunit_runner))
Command.hooks.install_named_hook("extend_command", setup_subunit_option, "setup_subunit_option")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-result-registry-4003.patch
Type: text/x-patch
Size: 11716 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090212/88dca2f1/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090212/88dca2f1/attachment-0001.pgp
More information about the bazaar
mailing list