diff options
author | Robert Collins <robertc@robertcollins.net> | 2013-07-16 00:18:48 +1200 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2013-07-16 00:18:48 +1200 |
commit | 5418052029a47afa9b4c326e8342c02b00486e7e (patch) | |
tree | af52adf58ae1bd463da0b82524ec5fa3816e02b8 | |
parent | 18ddf5aa8af1b0d339d20fb9a060451428a7e4dc (diff) | |
parent | b4814c9edef2a0d23b1bd52c775f69d9ed9ea216 (diff) | |
download | testrepository-5418052029a47afa9b4c326e8342c02b00486e7e.tar.gz |
* A new testr.conf option ``group_regex`` can be used for grouping
tests so that they get run in the same backend runner. (Matthew Treinish)
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/MANUAL.txt | 19 | ||||
-rw-r--r-- | testrepository/testcommand.py | 18 | ||||
-rw-r--r-- | testrepository/tests/test_testcommand.py | 10 |
4 files changed, 48 insertions, 2 deletions
@@ -8,6 +8,9 @@ NEXT (In development) CHANGES ------- +* A new testr.conf option ``group_regex`` can be used for grouping + tests so that they get run in the same backend runner. (Matthew Treinish) + * Fix Python 3.* support for entrypoints; the initial code was Python3 incompatible. (Robert Collins, Clark Boylan, #1187192) diff --git a/doc/MANUAL.txt b/doc/MANUAL.txt index cb76c66..788f93c 100644 --- a/doc/MANUAL.txt +++ b/doc/MANUAL.txt @@ -205,6 +205,25 @@ And then find tests with that tag:: $ testr last --subunit | subunit-filter -s --xfail --with-tag=worker-3 | subunit-ls > slave-3.list +Grouping Tests +~~~~~~~~~~~~~~ + +In certain scenarios you may want to group tests of a certain type together +so that they will be run by the same backend. The group_regex option in +.testr.conf permits this. When set, tests are grouped by the group(0) of any +regex match. Tests with no match are not grouped. + +For example, extending the python sample .testr.conf from the configuration +section with a group regex that will group python tests cases together by +class (the last . splits the class and test method):: + + [DEFAULT] + test_command=python -m subunit.run discover . $LISTOPT $IDOPTION + test_id_option=--load-list $IDFILE + test_list_option=--list + group_regex=([^\.]+\.)+ + + Remote or isolated test environments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/testrepository/testcommand.py b/testrepository/testcommand.py index d93881d..2cb4d50 100644 --- a/testrepository/testcommand.py +++ b/testrepository/testcommand.py @@ -73,6 +73,7 @@ testrconf_help = dedent(""" be adjusted if the paths are synched with different names. * instance_dispose -- dispose of one or more test running environments. Accepts $INSTANCE_IDS. + * group_regex -- If set group tests by the matched section of the test id. * $IDOPTION -- the variable to use to trigger running some specific tests. * $IDFILE -- A file created before the test command is run and deleted afterwards which contains a list of test ids, one per line. This can @@ -551,15 +552,28 @@ class TestCommand(Fixture): if e.message != "No option 'test_list_option' in section: 'DEFAULT'": raise raise ValueError("No test_list_option option present in .testr.conf") + try: + group_regex = parser.get('DEFAULT', 'group_regex') + except ConfigParser.NoOptionError: + group_regex = None + if group_regex: + def group_callback(test_id, regex=re.compile(group_regex)): + match = regex.match(test_id) + if match: + return match.group(0) + else: + group_callback = None if self.oldschool: listpath = os.path.join(self.ui.here, 'failing.list') result = self.run_factory(test_ids, cmd, listopt, idoption, self.ui, self.repository, listpath=listpath, parser=parser, - test_filters=test_filters, instance_source=self) + test_filters=test_filters, instance_source=self, + group_callback=group_callback) else: result = self.run_factory(test_ids, cmd, listopt, idoption, self.ui, self.repository, parser=parser, - test_filters=test_filters, instance_source=self) + test_filters=test_filters, instance_source=self, + group_callback=group_callback) return result def get_filter_tags(self): diff --git a/testrepository/tests/test_testcommand.py b/testrepository/tests/test_testcommand.py index b5b3374..605d490 100644 --- a/testrepository/tests/test_testcommand.py +++ b/testrepository/tests/test_testcommand.py @@ -221,6 +221,16 @@ class TestTestCommand(ResourcedTestCase): expected_cmd = 'foo ' self.assertEqual(expected_cmd, fixture.cmd) + def test_group_regex_option(self): + ui, command = self.get_test_ui_and_cmd() + self.set_config( + '[DEFAULT]\ntest_command=foo $IDOPTION\n' + 'test_id_option=--load-list $IDFILE\n' + 'group_regex=([^\\.]+\\.)+\n') + fixture = self.useFixture(command.get_run_command()) + self.assertEqual( + 'pkg.class.', fixture._group_callback('pkg.class.test_method')) + def test_extra_args_passed_in(self): ui, command = self.get_test_ui_and_cmd() self.set_config( |