From e9ad7b6d23030a8d73e4af811971213a771a8b9d Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Tue, 23 May 2017 18:45:01 -0400 Subject: [PATCH] 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: Cleber Rosa --- avocado/plugins/list.py | 13 +++++++++-- docs/source/GetStartedGuide.rst | 2 +- docs/source/WritingTests.rst | 4 ++-- man/avocado.rst | 2 +- selftests/functional/test_basic.py | 35 +++++++++++++++++++++++++++++- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/avocado/plugins/list.py b/avocado/plugins/list.py index 34e51c99..9bec95d3 100644 --- a/avocado/plugins/list.py +++ b/avocado/plugins/list.py @@ -78,7 +78,15 @@ class TestLister(object): stats[type_label.lower()] += 1 type_label = decorator(type_label) - test_matrix.append((type_label, id_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) diff --git a/docs/source/GetStartedGuide.rst b/docs/source/GetStartedGuide.rst index dcf31c1a..18a738e7 100644 --- a/docs/source/GetStartedGuide.rst +++ b/docs/source/GetStartedGuide.rst @@ -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 diff --git a/docs/source/WritingTests.rst b/docs/source/WritingTests.rst index 970ee42c..2f638557 100644 --- a/docs/source/WritingTests.rst +++ b/docs/source/WritingTests.rst @@ -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 diff --git a/man/avocado.rst b/man/avocado.rst index aaf9d583..15033255 100644 --- a/man/avocado.rst +++ b/man/avocado.rst @@ -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 diff --git a/selftests/functional/test_basic.py b/selftests/functional/test_basic.py index 6cbfedd2..67c03080 100644 --- a/selftests/functional/test_basic.py +++ b/selftests/functional/test_basic.py @@ -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 -- GitLab