@@ -42,6 +42,8 @@ def test_remap_argument(self):
4242 )
4343
4444 # Initialize rclpy and create node for checking topics
45+ stdout_log = ''
46+ stderr_log = ''
4547 rclpy .init ()
4648 node = None
4749 try :
@@ -69,11 +71,29 @@ def test_remap_argument(self):
6971 final_topics = [name for name ,
7072 types in final_topic_names_and_types ]
7173
74+ # Capture stdout and stderr before asserting
75+ if launch_proc_remapped and not remapped_topic_found :
76+ # Ensure the process is terminated before reading streams
77+ if launch_proc_remapped .poll () is None :
78+ launch_proc_remapped .terminate ()
79+ try :
80+ launch_proc_remapped .wait (timeout = 1 )
81+ except subprocess .TimeoutExpired :
82+ if launch_proc_remapped .poll () is None :
83+ launch_proc_remapped .kill ()
84+ launch_proc_remapped .wait (timeout = 1 )
85+ # Now read the streams
86+ stdout_bytes , stderr_bytes = launch_proc_remapped .communicate ()
87+ stdout_log = stdout_bytes .decode ('utf-8' , errors = 'replace' )
88+ stderr_log = stderr_bytes .decode ('utf-8' , errors = 'replace' )
89+
7290 # Verify /chatter_remapped IS in the list
7391 self .assertTrue (
7492 remapped_topic_found ,
75- f'Expected topic "/chatter_remapped" not found within { timeout } s. '
76- f'Final topics found: { final_topics } '
93+ f'Expected topic "/chatter_remapped" not found within { timeout } s.\n '
94+ f'Final topics found: { final_topics } \n '
95+ f'--- Launch STDOUT ---\n { stdout_log } \n '
96+ f'--- Launch STDERR ---\n { stderr_log } '
7797 )
7898
7999 # Verify /chatter is NOT in the list
@@ -93,13 +113,15 @@ def test_remap_argument(self):
93113
94114 finally :
95115 # Clean up the launch process
96- if launch_proc_remapped is not None :
116+ if launch_proc_remapped is not None and launch_proc_remapped .poll () is None :
117+ # Ensure process is terminated if not already done for logging
97118 launch_proc_remapped .terminate ()
98119 try :
99120 launch_proc_remapped .wait (timeout = 5 )
100121 except subprocess .TimeoutExpired :
101- launch_proc_remapped .kill ()
102- launch_proc_remapped .wait ()
122+ if launch_proc_remapped .poll () is None : # Check again if terminate failed
123+ launch_proc_remapped .kill ()
124+ launch_proc_remapped .wait ()
103125
104126
105127if __name__ == '__main__' :
0 commit comments