Skip to content

Commit

Permalink
Tags Filtering Fix
Browse files Browse the repository at this point in the history
Filtering now properly handles both verbose and non-verbose output modes
while checking for tag matches.
without changing the existing behavior that users expect when using
'avocado list -t <tag>'

Reference:      #6066
Signed-off-by: Harvey Lynden <hlynden@redhat.com>
  • Loading branch information
harvey0100 committed Dec 19, 2024
1 parent 6823e6b commit 51492c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
26 changes: 19 additions & 7 deletions avocado/plugins/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os

from avocado.core import exit_codes, parser_common_args
from avocado.core.tags import filter_tags_on_runnables
from avocado.core.output import LOG_UI, TERM_SUPPORT
from avocado.core.plugin_interfaces import CLICmd
from avocado.core.resolver import ReferenceResolutionResult
Expand Down Expand Up @@ -76,11 +77,7 @@ def _display(self, suite, matrix):
TERM_SUPPORT.header_str("Tag(s)"),
)

# Any kind of color, string format and term specific should be applied
# only during output/display phase. So this seems to be a better place
# for this:
matrix = self._prepare_matrix_for_display(matrix, verbose)

for line in iter_tabular_output(matrix, header=header, strip=True):
LOG_UI.debug(line)

Expand Down Expand Up @@ -133,6 +130,7 @@ def _display_extra(suite, verbose=True):
for key in sorted(suite.tags_stats):
LOG_UI.info("%s: %s", key, suite.tags_stats[key])


@staticmethod
def _get_resolution_matrix(suite):
"""Used for resolver.
Expand All @@ -142,21 +140,35 @@ def _get_resolution_matrix(suite):
"""
test_matrix = []
verbose = suite.config.get("core.verbose")
tags = suite.config.get("filter.by_tags.tags")
include_empty = suite.config.get("filter.by_tags.include_empty")
include_empty_key = suite.config.get("filter.by_tags.include_empty_key")

for resolution in suite.resolutions:
for runnable in resolution.resolutions:
if resolution.result != ReferenceResolutionResult.SUCCESS:
continue

if tags:
runnables = filter_tags_on_runnables(
[resolution], tags, include_empty, include_empty_key
)
else:
runnables = resolution.resolutions

for runnable in runnables:
if verbose:
tags = runnable.tags or {}
test_matrix.append(
(
runnable.kind,
runnable.identifier,
runnable.uri,
resolution.origin,
tags,
runnable.tags or {},
)
)
else:
test_matrix.append((runnable.kind, runnable.identifier))

return test_matrix

@staticmethod
Expand Down
17 changes: 17 additions & 0 deletions selftests/functional/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ def test_list_filter_by_tags(self):
(f"Avocado did not return rc " f"{exit_codes.AVOCADO_ALL_OK}:\n{result}"),
)
stdout_lines = result.stdout_text.splitlines()
self.assertRegex(
stdout_lines[1],
r"avocado-instrumented\s+.*examples/tests/cit_parameters.py:CitParameters.test\s+.*examples/tests/cit_parameters.py:CitParameters.test\s+avocado-instrumented\s+fast",
)
self.assertRegex(
stdout_lines[2],
r"avocado-instrumented\s+.*examples/tests/passtest.py:PassTest.test\s+.*examples/tests/passtest.py:PassTest.test\s+avocado-instrumented\s+fast",
)
self.assertRegex(
stdout_lines[3],
r"avocado-instrumented\s+.*examples/tests/tags.py:FastTest.test_fast\s+.*examples/tests/tags.py:FastTest.test_fast\s+avocado-instrumented\s+net,fast",
)
self.assertRegex(
stdout_lines[4],
r"avocado-instrumented\s+.*examples/tests/tags.py:FastTest.test_fast_other\s+.*examples/tests/tags.py:FastTest.test_fast_other\s+avocado-instrumented\s+net,fast",
)
self.assertEqual("", stdout_lines[5])
self.assertIn("TEST TYPES SUMMARY", stdout_lines)
self.assertIn("avocado-instrumented: 4", stdout_lines)
self.assertIn("TEST TAGS SUMMARY", stdout_lines)
Expand Down

0 comments on commit 51492c3

Please sign in to comment.