You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ROS-agnostic functionality can extend a Python launch file with both active tests (that run while the nodes are also running) and post-shutdown tests (which run once after all nodes have exited).
44
44
``launch_testing`` relies on the Python standard module `unittest <https://docs.python.org/3/library/unittest.html>`_ for the actual testing.
45
-
To get our integration tests run as part of ``colcon test``, we register the launch file in the ``CMakeLists.txt`` or `setup.py` file.`
45
+
To get our integration tests run as part of ``colcon test``, we register the launch file in the ``CMakeLists.txt`` or `setup.py` file.
46
46
47
47
For waiting on topics and triggering actions based on publisher availability, the `launch_testing_ros <https://docs.ros.org/en/{DISTRO}/p/launch_testing_ros/index.html>`_ package provides the `WaitForTopics <https://docs.ros.org/en/{DISTRO}/p/launch_testing_ros/launch_testing_ros.wait_for_topics.html>`_ utility, which simplifies topic subscription and waiting logic in integration tests.
48
48
@@ -61,7 +61,8 @@ We will cover both in this tutorial.
61
61
1.1 Imports
62
62
^^^^^^^^^^^
63
63
64
-
We first start by importing the Python modules we will be using. Key modules for testing include the general-purpose ``unittest``, ``launch_testing``, and the ``WaitForTopics`` utility from ``launch_testing_ros`` for convenient topic subscription and waiting logic.
64
+
We first start by importing the Python modules we will be using.
65
+
Key modules for testing include the general-purpose ``unittest``, ``launch_testing``, and the ``WaitForTopics`` utility from ``launch_testing_ros`` for convenient topic subscription and waiting logic.
65
66
66
67
.. code-block:: python
67
68
@@ -86,9 +87,11 @@ We first start by importing the Python modules we will be using. Key modules for
86
87
1.2 Generate the test description
87
88
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88
89
89
-
The function ``generate_test_description`` describes what to launch, similar to ``generate_launch_description`` in a ROS 2 Python launch file. In the example below, we launch the turtlesim node with immediate test execution (no arbitrary delays).
90
+
The function ``generate_test_description`` describes what to launch, similar to ``generate_launch_description`` in a ROS 2 Python launch file.
91
+
In the example below, we launch the turtlesim node with immediate test execution (no arbitrary delays).
90
92
91
-
The ``EnableRmwIsolation`` action ensures that ROS communication is isolated using ``rmw_test_fixture``, preventing test interference. The ``ReadyToTest`` action signals the test framework that the tests should begin.
93
+
The ``EnableRmwIsolation`` action ensures that ROS communication is isolated using ``rmw_test_fixture``, preventing test interference.
94
+
The ``ReadyToTest`` action signals the test framework that the tests should begin.
92
95
93
96
.. code-block:: python
94
97
@@ -122,7 +125,8 @@ In more complex integration test setups, you will probably want to launch a syst
122
125
1.3 Active tests using WaitForTopics
123
126
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124
127
125
-
The active tests interact with the running nodes. The ``WaitForTopics`` utility from ``launch_testing_ros`` provides a convenient way to:
128
+
The active tests interact with the running nodes.
129
+
The ``WaitForTopics`` utility from ``launch_testing_ros`` provides a convenient way to:
126
130
127
131
* Subscribe to topics and wait for them to become available
128
132
* Receive messages published on those topics
@@ -142,12 +146,15 @@ The simplest test verifies that a topic is published and messages are received:
This test creates a waiter that subscribes to the ``turtle1/pose`` topic expecting ``Pose`` messages. The `WaitForTopics` class automatically handles subscription and cleanup. The test asserts that the topic was received and at least one message was captured.
149
+
This test creates a waiter that subscribes to the ``turtle1/pose`` topic expecting ``Pose`` messages.
150
+
The `WaitForTopics` class automatically handles subscription and cleanup.
151
+
The test asserts that the topic was received and at least one message was captured.
146
152
147
153
1.3.2 Topic subscription with triggered action
148
154
"""""""""""""""""""""""""""""""""""""""""""""""
149
155
150
-
For more complex tests, you can trigger actions (such as publishing control messages) using the ``trigger`` parameter. This allows you to verify that nodes respond appropriately to a stimulus.
156
+
For more complex tests, you can trigger actions (such as publishing control messages) using the ``trigger`` parameter.
157
+
This allows you to verify that nodes respond appropriately to a stimulus.
151
158
152
159
First, define a trigger function that will be called once publishers are available:
153
160
@@ -320,8 +327,10 @@ Configure pytest discovery in ``setup.cfg``:
320
327
launch_test: launch testing integration tests
321
328
322
329
To run the tests, you can use the command:
330
+
323
331
.. code-block:: bash
324
-
colcon test --packages-select <your_package_name> --python-testing pytest
332
+
333
+
colcon test --packages-select your_package_name --python-testing pytest
0 commit comments