From 5bb7bab2d094edcd28ff73aa7d0eba68964a7a76 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Sun, 22 Jun 2025 22:23:55 -0500 Subject: [PATCH 1/2] Use rmw_test_fixture to isolate ros2cli tests Signed-off-by: Scott K Logan --- ros2action/test/test_cli.py | 12 +++++++---- ros2action/test/test_echo.py | 12 +++++++---- ros2cli/ros2cli/helpers.py | 2 -- ros2doctor/test/test_qos_compatibility.py | 13 +++++------- ros2lifecycle/test/test_cli.py | 13 +++++++----- ros2node/test/test_cli.py | 13 +++++++----- .../test/test_cli_duplicate_node_names.py | 14 +++++++------ ros2param/test/test_verb_dump.py | 8 +++++--- ros2param/test/test_verb_list.py | 9 +++++---- ros2param/test/test_verb_load.py | 11 +++++----- ros2service/test/test_cli.py | 13 +++++++----- ros2service/test/test_echo.py | 10 ++++++++-- ros2topic/test/test_cli.py | 20 ++++++------------- 13 files changed, 82 insertions(+), 68 deletions(-) diff --git a/ros2action/test/test_cli.py b/ros2action/test/test_cli.py index 5edb65adf..373e16fae 100644 --- a/ros2action/test/test_cli.py +++ b/ros2action/test/test_cli.py @@ -20,12 +20,14 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable import launch_testing import launch_testing.actions import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -51,23 +53,24 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'fibonacci_action_server.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', on_exit=[ ExecuteProcess( cmd=[sys.executable, path_to_action_server_executable], - additional_env=additional_env, ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env, ) ] ), @@ -115,8 +118,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_action_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } action_command_action = ExecuteProcess( cmd=['ros2', 'action', *arguments], diff --git a/ros2action/test/test_echo.py b/ros2action/test/test_echo.py index b3cc6bb46..70e498d64 100644 --- a/ros2action/test/test_echo.py +++ b/ros2action/test/test_echo.py @@ -21,6 +21,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable import launch_testing import launch_testing.actions @@ -28,6 +29,7 @@ import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools from osrf_pycommon.terminal_color import remove_ansi_escape_sequences @@ -221,23 +223,24 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'fibonacci_action_introspection.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', on_exit=[ ExecuteProcess( cmd=[sys.executable, path_to_action_server_executable], - additional_env=additional_env ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -256,8 +259,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_action_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } action_command_action = ExecuteProcess( cmd=['ros2', 'action', *arguments], name='ros2action-cli', output='screen', diff --git a/ros2cli/ros2cli/helpers.py b/ros2cli/ros2cli/helpers.py index 6c0c9ba09..abffcd489 100644 --- a/ros2cli/ros2cli/helpers.py +++ b/ros2cli/ros2cli/helpers.py @@ -127,8 +127,6 @@ def get_rmw_additional_env(rmw_implementation: str) -> Dict[str, str]: if rmw_implementation == 'rmw_zenoh_cpp': return { 'RMW_IMPLEMENTATION': rmw_implementation, - 'ZENOH_ROUTER_CHECK_ATTEMPTS': '-1', - 'ZENOH_CONFIG_OVERRIDE': 'scouting/multicast/enabled=true', 'RUST_LOG': 'z=error' } else: diff --git a/ros2doctor/test/test_qos_compatibility.py b/ros2doctor/test/test_qos_compatibility.py index 1a6a580f3..f5dab68bd 100644 --- a/ros2doctor/test/test_qos_compatibility.py +++ b/ros2doctor/test/test_qos_compatibility.py @@ -19,6 +19,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node @@ -27,6 +28,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -49,6 +51,7 @@ def generate_test_description(rmw_implementation): path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') additional_env = get_rmw_additional_env(rmw_implementation) additional_env['PYTHONUNBUFFERED'] = '1' + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] path_to_incompatible_talker_node_script = os.path.join( path_to_fixtures, 'talker_node_with_best_effort_qos.py') @@ -62,25 +65,21 @@ def generate_test_description(rmw_implementation): executable=sys.executable, arguments=[path_to_compatible_talker_node_script], remappings=[('chatter', 'compatible_chatter')], - additional_env=additional_env ) listener_node_compatible = Node( executable=sys.executable, arguments=[path_to_listener_node_script], remappings=[('chatter', 'compatible_chatter')], - additional_env=additional_env ) talker_node_incompatible = Node( executable=sys.executable, arguments=[path_to_incompatible_talker_node_script], remappings=[('chatter', 'incompatible_chatter')], - additional_env=additional_env ) listener_node_incompatible = Node( executable=sys.executable, arguments=[path_to_listener_node_script], remappings=[('chatter', 'incompatible_chatter')], - additional_env=additional_env ) return LaunchDescription([ @@ -89,6 +88,8 @@ def generate_test_description(rmw_implementation): cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -100,7 +101,6 @@ def generate_test_description(rmw_implementation): listener_node_compatible, launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -128,11 +128,8 @@ def setUpClass( @contextlib.contextmanager def launch_doctor_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' doctor_command_action = ExecuteProcess( cmd=['ros2', 'doctor', *arguments], - additional_env=additional_env, name='ros2doctor-cli', output='screen' ) diff --git a/ros2lifecycle/test/test_cli.py b/ros2lifecycle/test/test_cli.py index 5e67bfdaa..31074ec11 100644 --- a/ros2lifecycle/test/test_cli.py +++ b/ros2lifecycle/test/test_cli.py @@ -18,6 +18,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing @@ -25,6 +26,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -124,12 +126,15 @@ @launch_testing.parametrize('rmw_implementation', get_available_rmw_implementations()) def generate_test_description(rmw_implementation): additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -140,18 +145,15 @@ def generate_test_description(rmw_implementation): executable='simple_lifecycle_node', name='test_lifecycle_node', output='screen', - additional_env=additional_env ), Node( package='ros2lifecycle_test_fixtures', executable='simple_lifecycle_node', name='_hidden_test_lifecycle_node', output='screen', - additional_env=additional_env ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -170,8 +172,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_lifecycle_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } lifecycle_command_action = ExecuteProcess( cmd=['ros2', 'lifecycle', *arguments], additional_env=additional_env, diff --git a/ros2node/test/test_cli.py b/ros2node/test/test_cli.py index 7777db1b1..0dfe51523 100644 --- a/ros2node/test/test_cli.py +++ b/ros2node/test/test_cli.py @@ -21,6 +21,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node @@ -29,6 +30,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -52,12 +54,15 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'complex_node.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -67,17 +72,14 @@ def generate_test_description(rmw_implementation): executable=sys.executable, arguments=[path_to_complex_node_script], name='complex_node', - additional_env=additional_env ), Node( executable=sys.executable, arguments=[path_to_complex_node_script], name='_hidden_complex_node', - additional_env=additional_env ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -96,8 +98,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_node_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } node_command_action = ExecuteProcess( cmd=['ros2', 'node', *arguments], diff --git a/ros2node/test/test_cli_duplicate_node_names.py b/ros2node/test/test_cli_duplicate_node_names.py index 4d37463e3..b4b71b9ce 100644 --- a/ros2node/test/test_cli_duplicate_node_names.py +++ b/ros2node/test/test_cli_duplicate_node_names.py @@ -19,6 +19,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node @@ -27,6 +28,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -51,12 +53,15 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'complex_node.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -66,23 +71,19 @@ def generate_test_description(rmw_implementation): executable=sys.executable, arguments=[path_to_complex_node_script], name='complex_node', - additional_env=additional_env, ), Node( executable=sys.executable, arguments=[path_to_complex_node_script], name='complex_node', - additional_env=additional_env, ), Node( executable=sys.executable, arguments=[path_to_complex_node_script], name='complex_node_2', - additional_env=additional_env, ), launch_testing.actions.ReadyToTest(), ], - additional_env=additional_env ) ] ), @@ -101,8 +102,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_node_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } node_command_action = ExecuteProcess( cmd=['ros2', 'node', *arguments], additional_env=additional_env, diff --git a/ros2param/test/test_verb_dump.py b/ros2param/test/test_verb_dump.py index 3c1d1b47c..65d3f6167 100644 --- a/ros2param/test/test_verb_dump.py +++ b/ros2param/test/test_verb_dump.py @@ -21,12 +21,14 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing import launch_testing.actions import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -86,6 +88,7 @@ def generate_test_description(rmw_implementation): path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] # Parameter node test fixture path_to_parameter_node_script = os.path.join(path_to_fixtures, 'parameter_node.py') @@ -94,7 +97,6 @@ def generate_test_description(rmw_implementation): name=TEST_NODE, namespace=TEST_NAMESPACE, arguments=[path_to_parameter_node_script], - additional_env=additional_env ) return LaunchDescription([ @@ -103,6 +105,8 @@ def generate_test_description(rmw_implementation): cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -110,7 +114,6 @@ def generate_test_description(rmw_implementation): parameter_node, launch_testing.actions.ReadyToTest(), ], - additional_env=additional_env ) ] ), @@ -135,7 +138,6 @@ def setUpClass( def launch_param_dump_command(self, arguments): param_dump_command_action = ExecuteProcess( cmd=['ros2', 'param', 'dump', *arguments], - additional_env=get_rmw_additional_env(rmw_implementation), name='ros2param-dump-cli', output='screen' ) diff --git a/ros2param/test/test_verb_list.py b/ros2param/test/test_verb_list.py index 08ce8702c..208982472 100644 --- a/ros2param/test/test_verb_list.py +++ b/ros2param/test/test_verb_list.py @@ -21,12 +21,14 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing import launch_testing.actions import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -56,6 +58,7 @@ def generate_test_description(rmw_implementation): path_to_fixtures = Path(__file__).parent / 'fixtures' additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] # Parameter node test fixture path_to_parameter_node_script = path_to_fixtures / 'parameter_node.py' @@ -64,7 +67,6 @@ def generate_test_description(rmw_implementation): name=TEST_NODE, namespace=TEST_NAMESPACE, arguments=[str(path_to_parameter_node_script)], - additional_env=additional_env ) return LaunchDescription([ @@ -73,6 +75,8 @@ def generate_test_description(rmw_implementation): cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -80,7 +84,6 @@ def generate_test_description(rmw_implementation): parameter_node, launch_testing.actions.ReadyToTest(), ], - additional_env=additional_env ) ] ), @@ -103,10 +106,8 @@ def setUpClass( @contextlib.contextmanager def launch_param_list_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) param_list_command_action = ExecuteProcess( cmd=['ros2', 'param', 'list', *arguments], - additional_env=additional_env, name='ros2param-list-cli', output='screen' ) diff --git a/ros2param/test/test_verb_load.py b/ros2param/test/test_verb_load.py index f488edb54..1e2029a88 100644 --- a/ros2param/test/test_verb_load.py +++ b/ros2param/test/test_verb_load.py @@ -22,12 +22,14 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing import launch_testing.actions import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -106,6 +108,7 @@ def generate_test_description(rmw_implementation): path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] # Parameter node test fixture path_to_parameter_node_script = os.path.join(path_to_fixtures, 'parameter_node.py') @@ -114,7 +117,6 @@ def generate_test_description(rmw_implementation): name=TEST_NODE, namespace=TEST_NAMESPACE, arguments=[path_to_parameter_node_script], - additional_env=additional_env, ) return LaunchDescription([ @@ -123,6 +125,8 @@ def generate_test_description(rmw_implementation): cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -130,7 +134,6 @@ def generate_test_description(rmw_implementation): parameter_node, launch_testing.actions.ReadyToTest(), ], - additional_env=additional_env ) ] ), @@ -153,10 +156,8 @@ def setUpClass( @contextlib.contextmanager def launch_param_load_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) param_load_command_action = ExecuteProcess( cmd=['ros2', 'param', 'load', *arguments], - additional_env=additional_env, name='ros2param-load-cli', output='screen' ) @@ -169,10 +170,8 @@ def launch_param_load_command(self, arguments): @contextlib.contextmanager def launch_param_dump_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) param_dump_command_action = ExecuteProcess( cmd=['ros2', 'param', 'dump', *arguments], - additional_env=additional_env, name='ros2param-dump-cli', output='screen' ) diff --git a/ros2service/test/test_cli.py b/ros2service/test/test_cli.py index 1d8f97324..f3dc83cf8 100644 --- a/ros2service/test/test_cli.py +++ b/ros2service/test/test_cli.py @@ -21,6 +21,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing @@ -28,6 +29,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -69,12 +71,15 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'echo_server.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -85,7 +90,6 @@ def generate_test_description(rmw_implementation): arguments=[path_to_echo_server_script], name='echo_server', namespace='my_ns', - additional_env=additional_env, ), Node( executable=sys.executable, @@ -93,11 +97,9 @@ def generate_test_description(rmw_implementation): name='_hidden_echo_server', namespace='my_ns', remappings=[('echo', '_echo')], - additional_env=additional_env, ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -126,8 +128,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_service_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } service_command_action = ExecuteProcess( cmd=['ros2', 'service', *arguments], additional_env=additional_env, diff --git a/ros2service/test/test_echo.py b/ros2service/test/test_echo.py index b9537aa9b..678cb1499 100644 --- a/ros2service/test/test_echo.py +++ b/ros2service/test/test_echo.py @@ -21,6 +21,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node import launch_testing @@ -28,6 +29,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -93,12 +95,15 @@ def generate_test_description(rmw_implementation): os.path.dirname(__file__), 'fixtures', 'introspectable.py' ) additional_env = get_rmw_additional_env(rmw_implementation) + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -131,8 +136,9 @@ def setUpClass( ): @contextlib.contextmanager def launch_service_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' + additional_env = { + 'PYTHONUNBUFFERED': '1', + } service_command_action = ExecuteProcess( cmd=['ros2', 'service', *arguments], additional_env=additional_env, diff --git a/ros2topic/test/test_cli.py b/ros2topic/test/test_cli.py index f04c70743..c21278d43 100644 --- a/ros2topic/test/test_cli.py +++ b/ros2topic/test/test_cli.py @@ -22,6 +22,7 @@ from launch import LaunchDescription from launch.actions import ExecuteProcess +from launch.actions import SetEnvironmentVariable from launch_ros.actions import Node @@ -30,6 +31,7 @@ import launch_testing.asserts import launch_testing.markers import launch_testing.tools +from launch_testing_ros.actions import EnableRmwIsolation import launch_testing_ros.tools import pytest @@ -52,6 +54,7 @@ def generate_test_description(rmw_implementation): path_to_fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') additional_env = get_rmw_additional_env(rmw_implementation) additional_env['PYTHONUNBUFFERED'] = '1' + set_env_actions = [SetEnvironmentVariable(k, v) for k, v in additional_env.items()] path_to_talker_node_script = os.path.join(path_to_fixtures, 'talker_node.py') path_to_listener_node_script = os.path.join(path_to_fixtures, 'listener_node.py') @@ -59,18 +62,15 @@ def generate_test_description(rmw_implementation): executable=sys.executable, arguments=[path_to_talker_node_script], remappings=[('chatter', '_hidden_chatter')], - additional_env=additional_env ) talker_node_action = Node( executable=sys.executable, arguments=[path_to_talker_node_script], - additional_env=additional_env ) listener_node_action = Node( executable=sys.executable, arguments=[path_to_listener_node_script], remappings=[('chatter', 'chit_chatter')], - additional_env=additional_env ) path_to_repeater_node_script = os.path.join(path_to_fixtures, 'repeater_node.py') @@ -81,14 +81,12 @@ def generate_test_description(rmw_implementation): name='array_repeater', remappings=[('/array_repeater/output', '/arrays')], output='screen', - additional_env=additional_env ) defaults_repeater_node_action = Node( executable=sys.executable, arguments=[path_to_repeater_node_script, 'test_msgs/msg/Defaults'], name='defaults_repeater', remappings=[('/defaults_repeater/output', '/defaults')], - additional_env=additional_env, ) bounded_sequences_repeater_node_action = Node( executable=sys.executable, @@ -97,7 +95,6 @@ def generate_test_description(rmw_implementation): ], name='bounded_sequences_repeater', remappings=[('/bounded_sequences_repeater/output', '/bounded_sequences')], - additional_env=additional_env ) unbounded_sequences_repeater_node_action = Node( executable=sys.executable, @@ -106,7 +103,6 @@ def generate_test_description(rmw_implementation): ], name='unbounded_sequences_repeater', remappings=[('/unbounded_sequences_repeater/output', '/unbounded_sequences')], - additional_env=additional_env ) path_to_controller_node_script = os.path.join(path_to_fixtures, 'controller_node.py') @@ -114,7 +110,6 @@ def generate_test_description(rmw_implementation): cmd_vel_controller_node_action = Node( executable=sys.executable, arguments=[path_to_controller_node_script], - additional_env=additional_env ) return LaunchDescription([ @@ -123,6 +118,8 @@ def generate_test_description(rmw_implementation): cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ + *set_env_actions, + EnableRmwIsolation(), ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', @@ -141,7 +138,6 @@ def generate_test_description(rmw_implementation): cmd_vel_controller_node_action, launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ), @@ -166,11 +162,8 @@ def setUpClass( @contextlib.contextmanager def launch_topic_command(self, arguments): - additional_env = get_rmw_additional_env(rmw_implementation) - additional_env['PYTHONUNBUFFERED'] = '1' topic_command_action = ExecuteProcess( cmd=['ros2', 'topic', *arguments], - additional_env=additional_env, name='ros2topic-cli', output='screen' ) @@ -842,13 +835,12 @@ def test_topic_pub_once(self): assert topic_command.exit_code == launch_testing.asserts.EXIT_OK def test_topic_pub_once_matching_two_listeners( - self, launch_service, proc_info, proc_output, path_to_listener_node_script, additional_env + self, launch_service, proc_info, proc_output, path_to_listener_node_script ): second_listener_node_action = Node( executable=sys.executable, arguments=[path_to_listener_node_script], remappings=[('chatter', 'chit_chatter')], - additional_env=additional_env, name='second_listener', ) with launch_testing.tools.launch_process( From e82bb0583809180b2dc40a72670e54a1e6efd8ca Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Mon, 7 Jul 2025 14:49:52 -0500 Subject: [PATCH 2/2] Drop some unnecessary additional_env Signed-off-by: Scott K Logan --- ros2service/test/test_echo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ros2service/test/test_echo.py b/ros2service/test/test_echo.py index 678cb1499..92eb6a451 100644 --- a/ros2service/test/test_echo.py +++ b/ros2service/test/test_echo.py @@ -113,11 +113,9 @@ def generate_test_description(rmw_implementation): executable=sys.executable, arguments=[path_to_introspectable_script], name='introspectable_service', - additional_env=additional_env, ), launch_testing.actions.ReadyToTest() ], - additional_env=additional_env ) ] ),