Skip to content

Commit 1d6681e

Browse files
committed
Refactor Integration.rst for clarity and formatting improvements
1 parent 519f795 commit 1d6681e

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

source/Developer-Tools/Debugging/Testing/Integration.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The main tool in use here is the `launch_testing <https://docs.ros.org/en/{DISTR
4242
(`launch_testing repository <https://github.com/ros2/launch/tree/{REPOS_FILE_BRANCH}/launch_testing>`_).
4343
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).
4444
``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.
4646

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

@@ -61,7 +61,8 @@ We will cover both in this tutorial.
6161
1.1 Imports
6262
^^^^^^^^^^^
6363

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

6667
.. code-block:: python
6768
@@ -86,9 +87,11 @@ We first start by importing the Python modules we will be using. Key modules for
8687
1.2 Generate the test description
8788
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8889

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

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

9396
.. code-block:: python
9497
@@ -122,7 +125,8 @@ In more complex integration test setups, you will probably want to launch a syst
122125
1.3 Active tests using WaitForTopics
123126
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124127

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:
126130

127131
* Subscribe to topics and wait for them to become available
128132
* Receive messages published on those topics
@@ -142,12 +146,15 @@ The simplest test verifies that a topic is published and messages are received:
142146
assert waiter.topics_received() == {"turtle1/pose"}
143147
assert len(waiter.received_messages("turtle1/pose")) >= 1
144148
145-
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.
146152

147153
1.3.2 Topic subscription with triggered action
148154
"""""""""""""""""""""""""""""""""""""""""""""""
149155

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

152159
First, define a trigger function that will be called once publishers are available:
153160

@@ -320,8 +327,10 @@ Configure pytest discovery in ``setup.cfg``:
320327
launch_test: launch testing integration tests
321328
322329
To run the tests, you can use the command:
330+
323331
.. 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
325334
326335
327336

0 commit comments

Comments
 (0)