Fix the -l/--list-tests argument for tempest run

The tempest run to stestr migration accidently removed the list command.
This commit adds the functionality back and adds a unit test to ensure
this doesn't happen in the future.

Change-Id: Ibc74887dec98f5d9adce56c235d28b19d0a94a63
This commit is contained in:
Matthew Treinish 2018-02-22 12:11:46 -05:00
parent 3e97aae829
commit f9902eca55
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
2 changed files with 26 additions and 2 deletions

View File

@ -161,8 +161,13 @@ class TempestRun(command.Command):
else:
pass
if not (parsed_args.config_file or parsed_args.workspace):
regex = self._build_regex(parsed_args)
regex = self._build_regex(parsed_args)
if parsed_args.list_tests:
return_code = commands.list_command(
filters=regex, whitelist_file=parsed_args.whitelist_file,
blacklist_file=parsed_args.blacklist_file)
elif not (parsed_args.config_file or parsed_args.workspace):
serial = not parsed_args.parallel
return_code = commands.run_command(
filters=regex, subunit_out=parsed_args.subunit,

View File

@ -21,6 +21,7 @@ import tempfile
import fixtures
import mock
import six
from tempest.cmd import run
from tempest.tests import base
@ -93,6 +94,7 @@ class TestRunReturnCode(base.TestCase):
msg = ("Running %s got an unexpected returncode\n"
"Stdout: %s\nStderr: %s" % (' '.join(cmd), out, err))
self.assertEqual(p.returncode, expected, msg)
return out, err
def test_tempest_run_passes(self):
self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
@ -104,6 +106,23 @@ class TestRunReturnCode(base.TestCase):
def test_tempest_run_fails(self):
self.assertRunExit(['tempest', 'run'], 1)
def test_run_list(self):
subprocess.call(['stestr', 'init'])
out, err = self.assertRunExit(['tempest', 'run', '-l'], 0)
tests = out.split()
tests = sorted([six.text_type(x.rstrip()) for x in tests if x])
result = [
six.text_type('tests.test_failing.FakeTestClass.test_pass'),
six.text_type('tests.test_failing.FakeTestClass.test_pass_list'),
six.text_type('tests.test_passing.FakeTestClass.test_pass'),
six.text_type('tests.test_passing.FakeTestClass.test_pass_list'),
]
# NOTE(mtreinish): on python 3 the subprocess prints b'' around
# stdout.
if six.PY3:
result = ["b\'" + x + "\'" for x in result]
self.assertEqual(result, tests)
class TestTakeAction(base.TestCase):
def test_workspace_not_registered(self):