Do rostest test nodes publish to rosout?

Hello all,

I posted this question to ROS answers page but did not get any help:

Reposting here to see if I can get any help. Feel free to continue the discussion over there or start a new one here.

Some background. I am new to writing unit tests in gtests/rostest. So a lot of this might be just me unable to find that awesome link which will clear everything up. The course on Robot Ignite Academy focuses on python unittests and not gtest CPP. There is one Construct video on Youtube for CPP/gtests but that does not solve my problem, Anyway, here it goes:

My node under test: This node is only subscribing to /rosout_agg . Think of this as some sort of diagnostics node.

My test scenario: I want to publish several series of messages to /rosout from my test cases and see how my diagnostics node responds to this. So I was thinking I will just use the log statements such as ROS_INFO , ROS_WARN and ROS_ERROR to publish my test case messages onto /rosout . I am not directly publishing to this topic. Rather just using the log statements.

My rostest file looks like follows:

<?xml version="1.0"?>
    <node pkg="diagnostics" type="diagnostics" name="diagnostics_node"  output="screen"/>
    <test test-name="diagnostics_test_node" pkg="diagnostics" type="diagnostics_test_node"/>
  • When I run this file using rostest , my diagnostics node is not picking up any messages from /rosout_agg . The subscriber callback in my node under test never gets called.
  • Note that, when I run my diagnostics_test_node as just a gtest and my diagnostics node separately, everything is working as expected.

So the question I have is, do the test nodes that rostest starts automatically start a rosout as well (The log XML file does not seem to have any mention of starting rosout)? What happens to the messages created by the log statements in the test node in this case? Should I be directly publishing to /rosout instead of using log statements? Any other ideas on how I should be testing a stream of messages from /rosout_agg ?

Please let me know if I can expand on my question!

Hi @swarooph.nirmal,

I tried to find an answer for this, but it seems that during tests the log messages are not really sent to /rosout.

I created a ros test file to test the concept, and the messages are never received on /rosout.
This is the test I used:

#! /usr/bin/env python
from rosgraph_msgs.msg import Log

import rospy
import unittest
import rostest

def callback(data):
 rospy.logfatal('I am the fatal and received: %s' % data)

class MyTestCase(unittest.TestCase):

  def test_whatever(self):
     rospy.init_node('subscriber_node', anonymous=True)
     rospy.Subscriber("/rosout", Log, callback)
     rospy.logwarn('Sleeping 10 seconds to see whether test goes ok')

     from time import sleep
     count = 1
     while True:
        count +=1 
        rospy.logwarn('I am the legend %d' % count)
        if count == 5: break

if __name__ == "__main__":
  rostest.rosrun('diagnostics', 'diagnostics_test_node', MyTestCase)

With the code above I see the logwarn is printed to screen, but the logfatal is never printed.

So what I can say is, from this test, it seems that during tests the log messages are not really sent to /rosout.

1 Like

You are correct. Just to complete this answer, the approach that seemed to work for me is to directly publish to the rosout_agg topic from the test case. I constructed the rosgraph log message and published using a publisher.