Ask Your Question

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

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


The class recently added to launch_testing ( ) 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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 1,160 times

Last updated: Aug 28 '18