提交 e9ad7b6d 编写于 作者: C Cleber Rosa

avocado list command: also list test tags

Test tags (via docstring directives) have been supported in Avocado
for a number of releases, but up until now user would only be able to
see the tags on their tests by resorting to the source code.

This was already difficult when the tags where set only at the class
level, now that they can be set both on the class and method
docstring, users would have to do the "math" on their minds.

Let's display the test tags when the verbose switch is given to the
list command to make the life of users easier.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 6e9b1625
......@@ -78,6 +78,14 @@ class TestLister(object):
stats[type_label.lower()] += 1
type_label = decorator(type_label)
if self.args.verbose:
if 'tags' in params:
tags = params['tags']
else:
tags = set()
tags = ",".join(tags)
test_matrix.append((type_label, id_label, tags))
else:
test_matrix.append((type_label, id_label))
return test_matrix, stats
......@@ -86,7 +94,8 @@ class TestLister(object):
header = None
if self.args.verbose:
header = (output.TERM_SUPPORT.header_str('Type'),
output.TERM_SUPPORT.header_str('Test'))
output.TERM_SUPPORT.header_str('Test'),
output.TERM_SUPPORT.header_str('Tag(s)'))
for line in astring.iter_tabular_output(test_matrix, header=header):
LOG_UI.debug(line)
......
......@@ -264,7 +264,7 @@ treated as simple tests. You can also give the ``--verbose`` or ``-V`` flag to
display files that were found by Avocado, but are not considered Avocado tests::
$ avocado list examples/gdb-prerun-scripts/ -V
Type file
Type Test Tag(s)
NOT_A_TEST examples/gdb-prerun-scripts/README
NOT_A_TEST examples/gdb-prerun-scripts/pass-sigusr1
......
......@@ -1183,7 +1183,7 @@ Then you implement your actual test using that derived class, in
If you try to list the tests in that file, this is what you'll get::
scripts/avocado list mytest.py -V
Type Test
Type Test Tag(s)
NOT_A_TEST mytest.py
ACCESS_DENIED: 0
......@@ -1220,7 +1220,7 @@ the example below::
Now, trying to list the tests on the ``mytest.py`` file again::
scripts/avocado list mytest.py -V
Type Test
Type Test Tag(s)
INSTRUMENTED mytest.py:MyTest.test1
INSTRUMENTED mytest.py:MyTest.test2
......
......@@ -604,7 +604,7 @@ the `--verbose`, or `-V` flag to display files that were detected but
are not avocado tests, along with summary information::
$ avocado list examples/gdb-prerun-scripts/ -V
Type file
Type Test Tag(s)
NOT_A_TEST examples/gdb-prerun-scripts/README
NOT_A_TEST examples/gdb-prerun-scripts/pass-sigusr1
......
......@@ -80,6 +80,18 @@ class MyTest(Test):
'''
VALID_PYTHON_TEST_WITH_TAGS = '''
from avocado import Test
class MyTest(Test):
def test(self):
"""
:avocado: tags=BIG_TAG_NAME
"""
pass
'''
REPORTS_STATUS_AND_HANG = '''
from avocado import Test
import time
......@@ -920,11 +932,32 @@ class PluginsTest(AbsPluginsTest, unittest.TestCase):
self.assertEqual(result.exit_status, exit_codes.AVOCADO_ALL_OK,
"Avocado did not return rc %d:\n%s"
% (exit_codes.AVOCADO_ALL_OK, result))
exp = ("Type Test\nMISSING this-wont-be-matched\n\nEXTERNAL: 0\n"
exp = ("Type Test Tag(s)\n"
"MISSING this-wont-be-matched \n\n"
"EXTERNAL: 0\n"
"MISSING: 1\n")
self.assertEqual(exp, result.stdout, "Stdout mismatch:\n%s\n\n%s"
% (exp, result))
def test_list_verbose_tags(self):
"""
Runs list verbosely and check for tag related output
"""
os.chdir(basedir)
test = script.make_script(os.path.join(self.base_outputdir, 'test.py'),
VALID_PYTHON_TEST_WITH_TAGS)
cmd_line = ("%s list --loaders file --verbose %s" % (AVOCADO,
test))
result = process.run(cmd_line, ignore_status=True)
self.assertEqual(result.exit_status, exit_codes.AVOCADO_ALL_OK,
"Avocado did not return rc %d:\n%s"
% (exit_codes.AVOCADO_ALL_OK, result))
stdout_lines = result.stdout.splitlines()
self.assertIn("Tag(s)", stdout_lines[0])
full_test_name = "%s:MyTest.test" % test
self.assertEquals("INSTRUMENTED %s BIG_TAG_NAME" % full_test_name,
stdout_lines[1])
def test_plugin_list(self):
os.chdir(basedir)
cmd_line = '%s plugins' % AVOCADO
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册