ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can I test a ROS2 nodes ROS interface with tests implemented in Python?

asked 2018-08-28 12:17:39 -0500

thinwybk gravatar image

The demos repo tests ROS2 nodes implemented in C++ with pytest. https://github.com/ros2/demos/blob/ma... The tests check the stdout output of the nodes. It is not obvious how to define pytest tests in Python to provide topics to a ROS2 node and assert against topic output of the ROS2 node. Are there other examples I could read to get how this works?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-28 19:38:40 -0500

Geoff gravatar image

You can use the rclpy client library to create topics in your tests that talk to the node being tested. It is no different to using any other library in your test code. You can use lambdas for topic callbacks to make it easier to manage the test code, and you can use the event queuing API to do things like require the node under test to respond within a certain time, or to wait for one single response.

You should play with when to create the node and topic (in the test's setup, or the whole test group's setup, for example) to find the most efficient test execution without creating hidden state that can impact later tests.

edit flag offensive delete link more

Comments

The class recently added to launch_testing ( https://github.com/ros2/launch/pull/131 ) makes it easier to write launch files in Python and mark individual processes as tests. The PR also references two example using this approach.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-08-29 16:48:49 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-08-28 12:17:39 -0500

Seen: 1,627 times

Last updated: Aug 28 '18