# Question | Exclude empty suites from reports?

**URL:** <https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162>\
**Category:** Robot Framework\
**Created:** [8 May 2020 18:53 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162 "2020-05-08T18:53:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [8 May 2020 18:53 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/1 "2020-05-08T18:53:08Z")

</div>

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:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/1X/fc7ac25bc36a9741b88eb34fd9fef2d353a57c84.png)

**Is there any way to exclude empty test suites from either the report created by robot or the merged report created by rebot?**

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [8 May 2020 19:40 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/2 "2020-05-08T19:40:15Z")

</div>

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.

```python
"""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

```

[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#example-exclude-tests-by-name](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#example-exclude-tests-by-name)

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [8 May 2020 19:50 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/3 "2020-05-08T19:50:32Z")

</div>

I am running it using:

> robot --RunEmptySuite -i tag1 -e tag2 suite

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'.`

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/1X/227b61952319172366513d3fc8de30e712ac166c.png)

I will take a look at SuiteVisitor, thank you.

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [8 May 2020 20:03 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/4 "2020-05-08T20:03:26Z")

</div>

This is a `prerunmodifier` of DataDriver that deletes all suites that run pass last time.  
Here you see how to “parse” the results of an output.xml.

the ` __init__ (self, original_output_xml)` get the path to the output.xml.

> <https://github.com/Snooz82/robotframework-datadriver/blob/master/src/DataDriver/rerunfailed.py>

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [8 May 2020 20:15 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/5 "2020-05-08T20:15:30Z")

</div>

`rebot --prerebotmodifier DeleteEmptySuites.py --output output_new.xml output.xml`

just delete the most stuff from the example code … 😉

```python
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

```

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [8 May 2020 20:32 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/6 "2020-05-08T20:32:19Z")

</div>

Thanks so much for all the help!

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!

---

<div class="post-metadata">

**Author:** ![Noordsestern](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/noordsestern/32/4270_2.png) [@Noordsestern](https://forum.robotframework.org/u/Noordsestern)\
**Post date:** [9 May 2020 07:48 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/7 "2020-05-09T07:48:34Z")

</div>

I believe, `exit 0` is windows specific. Robot offers an inbuilt switch `--nostatusrc` to ignore failed runs:

`robot --nostatusrc -i flaky -i development .`

See all options here: [https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/Appendices/CommandLineOptions.rst](https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/Appendices/CommandLineOptions.rst)

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [10 May 2020 16:32 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/8 "2020-05-10T16:32:14Z")

</div>

Its working on windows and linux but I will give that a try tomorrow though, thank you.

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [11 May 2020 15:26 UTC](https://forum.robotframework.org/t/question-exclude-empty-suites-from-reports/162/9 "2020-05-11T15:26:07Z")

</div>

Tried that out today, works great, thanks!
