Merge "Fix error when without --regex option"

This commit is contained in:
Jenkins 2017-03-03 00:04:01 +00:00 committed by Gerrit Code Review
commit 07e0b06f88
2 changed files with 17 additions and 1 deletions

View File

@ -19,7 +19,10 @@ import subprocess
def _get_test_list(regex, env=None):
env = env or copy.deepcopy(os.environ)
proc = subprocess.Popen(['testr', 'list-tests', regex], env=env,
testr_args = ['testr', 'list-tests']
if regex:
testr_args.append(regex)
proc = subprocess.Popen(testr_args, env=env,
stdout=subprocess.PIPE, universal_newlines=True)
out = proc.communicate()[0]
raw_test_list = out.split('\n')

View File

@ -174,3 +174,16 @@ class TestGetTestList(base.TestCase):
def test__get_test_list(self):
test_list = os_testr._get_test_list('test__get_test_list')
self.assertIn('test__get_test_list', test_list[0])
def test__get_test_list_regex_is_empty(self):
test_list = os_testr._get_test_list('')
self.assertIn('', test_list[0])
def test__get_test_list_regex_is_none(self):
test_list = os_testr._get_test_list(None)
# NOTE(masayukig): We should get all of the tests. So we should have
# more than one test case.
self.assertGreater(len(test_list), 1)
self.assertIn('os_testr.tests.test_regex_builder.'
'TestGetTestList.test__get_test_list_regex_is_none',
test_list)