@@ -42,6 +42,8 @@ def test_remap_argument(self):
42
42
)
43
43
44
44
# Initialize rclpy and create node for checking topics
45
+ stdout_log = ''
46
+ stderr_log = ''
45
47
rclpy .init ()
46
48
node = None
47
49
try :
@@ -69,11 +71,29 @@ def test_remap_argument(self):
69
71
final_topics = [name for name ,
70
72
types in final_topic_names_and_types ]
71
73
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
+
72
90
# Verify /chatter_remapped IS in the list
73
91
self .assertTrue (
74
92
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 } '
77
97
)
78
98
79
99
# Verify /chatter is NOT in the list
@@ -93,13 +113,15 @@ def test_remap_argument(self):
93
113
94
114
finally :
95
115
# 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
97
118
launch_proc_remapped .terminate ()
98
119
try :
99
120
launch_proc_remapped .wait (timeout = 5 )
100
121
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 ()
103
125
104
126
105
127
if __name__ == '__main__' :
0 commit comments