Rostest in Python not subscribing to a topic

asked 2021-11-26 06:52:19 -0500

mojer gravatar image

updated 2021-12-08 15:59:23 -0500

osilva gravatar image

Hi there,

I'm performing testing with rospy and rostest. I have some nodes running that are constantly publishing on a topic. But the subscribers I create inside the rostest are not able to connect to the topics. if run the same code in a normal node, it works perfectly but when I do it inside the rostest it is not able to received the topic. This is my code:

class TestRosComunication(unittest.TestCase):

    def test_robot_control(self):
        rospy.init_node("test_node")
        time.sleep(2)
        robot=RobotJointControl()

        while(robot.sub.get_num_connections()==0):
            rospy.sleep(1)
            rospy.loginfo("waiting for publishers")
        joints=robot.getCurrentJoints()

        print(joints)
        self.assertTrue(joints is not None)

   if __name__ == '__main__':
    import rostest

    rostest.rosrun(PKG, 'test_ros_test', TestRosComunication)

The subscriber is create in the constructor of RobotJointControl. And also when running the above code, and typing rosnode list the node test_node does not appear.

edit retag flag offensive close merge delete

Comments

Have you sourced your package?

osilva gravatar image osilva  ( 2021-11-29 21:00:49 -0500 )edit

Try initializing the ros node before you run the tests with rostest.

JeremyRoy gravatar image JeremyRoy  ( 2021-12-03 13:38:53 -0500 )edit