I currently have a Jenkins pipeline that is running sets of tests based on tags selected. This of course sometimes leads to empty test suites that don;t have any tests matching the tag selection like so:
How do you execute robot?
I have never seen this behavior.
When i call robot --exclude tag suite only the suites with test cases are in the log.
Can you give more details?
Solution:
One solution that would work would be a SuiteVisitor that reworks the output.xml and deletes all suite that don´t have a test case, but i think there are easier ways.
It would work like this example in the docs.
"""Pre-run modifier that excludes tests by their name.
Tests to exclude are specified by using a pattern that is both case and space
insensitive and supports '*' (match anything) and '?' (match single character)
as wildcards.
"""
from robot.api import SuiteVisitor
from robot.utils import Matcher
class ExcludeTests(SuiteVisitor):
def __init__(self, pattern):
self.matcher = Matcher(pattern)
def start_suite(self, suite):
"""Remove tests that match the given pattern."""
suite.tests = [t for t in suite.tests if not self._is_excluded(t)]
def _is_excluded(self, test):
return self.matcher.match(test.name) or self.matcher.match(test.longname)
def end_suite(self, suite):
"""Remove suites that are empty after removing tests."""
suite.suites = [s for s in suite.suites if s.test_count > 0]
def visit_test(self, test):
"""Avoid visiting tests and their keywords to save a little time."""
pass
If I were to remove --RunEmptySuite it would indeed exclude them but it counts them as a failure which propagates up to Jenkins: [ ERROR ] Suite 'Buildings' contains no tests matching tag 'dev AND About' and not matching tags 'doNotRun', 'inDevelopment' or 'Flaky'.
just delete the most stuff from the example code …
from robot.api import SuiteVisitor
class DeleteEmptySuites(SuiteVisitor):
def end_suite(self, suite):
"""Remove suites that are empty."""
suite.suites = [s for s in suite.suites if s.test_count > 0]
def visit_test(self, test):
"""Avoid visiting tests and their keywords to save a little time."""
pass
In the end however while working through this I realized my mistake… I am currently running these tests from a shell script and I just needed to add || exit 0
to ignore the robot execution status. Then when I use the robot publisher in Jenkins it will appropriately set my Success, Unstable, or Failure status based on the actual tests run.
I will certainly keep in mind the suggestion though as I did not know about the prerebotmodifier at all!