Rostest in Python not subscribing to a topic
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.
Have you sourced your package?
Try initializing the ros node before you run the tests with rostest.