diff --git a/test_tf2/CMakeLists.txt b/test_tf2/CMakeLists.txt index afb199d1f..3ae1ffed2 100644 --- a/test_tf2/CMakeLists.txt +++ b/test_tf2/CMakeLists.txt @@ -15,6 +15,7 @@ endif() if (BUILD_TESTING) find_package(ament_cmake_gtest REQUIRED) + find_package(ament_cmake_ros REQUIRED) find_package(ament_cmake_ros_core REQUIRED) find_package(builtin_interfaces REQUIRED) # Work around broken find module in AlmaLinux/RHEL eigen3-devel from PowerTools repo @@ -34,7 +35,7 @@ if (BUILD_TESTING) ament_find_gtest() - ament_add_gtest(buffer_core_test test/buffer_core_test.cpp) + ament_add_ros_isolated_gtest(buffer_core_test test/buffer_core_test.cpp) if(TARGET buffer_core_test) target_link_libraries(buffer_core_test ament_cmake_ros_core::ament_ros_defaults @@ -46,7 +47,7 @@ if (BUILD_TESTING) tf2_ros::tf2_ros) endif() - ament_add_gtest(test_message_filter test/test_message_filter.cpp) + ament_add_ros_isolated_gtest(test_message_filter test/test_message_filter.cpp) if(TARGET test_message_filter) target_link_libraries(test_message_filter ament_cmake_ros_core::ament_ros_defaults @@ -118,7 +119,7 @@ if (BUILD_TESTING) add_launch_test(test/static_publisher.launch.py) endif() - ament_add_gtest(test_tf2_bullet test/test_tf2_bullet.cpp) + ament_add_ros_isolated_gtest(test_tf2_bullet test/test_tf2_bullet.cpp) if(TARGET test_tf2_bullet) target_link_libraries(test_tf2_bullet ament_cmake_ros_core::ament_ros_defaults diff --git a/test_tf2/package.xml b/test_tf2/package.xml index 52a3347fa..eba3f9625 100644 --- a/test_tf2/package.xml +++ b/test_tf2/package.xml @@ -29,6 +29,7 @@ tf2_ros ament_cmake_gtest + ament_cmake_ros ament_cmake_ros_core launch_ros launch_testing_ament_cmake diff --git a/tf2_ros/CMakeLists.txt b/tf2_ros/CMakeLists.txt index 258c20b21..fd5ae3532 100644 --- a/tf2_ros/CMakeLists.txt +++ b/tf2_ros/CMakeLists.txt @@ -146,9 +146,9 @@ if(BUILD_TESTING) ament_lint_cmake() ament_uncrustify(LANGUAGE "c++") - find_package(ament_cmake_gtest REQUIRED) + find_package(ament_cmake_ros REQUIRED) - ament_add_gtest(test_buffer test/test_buffer.cpp) + ament_add_ros_isolated_gtest(test_buffer test/test_buffer.cpp) target_link_libraries(test_buffer ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -156,7 +156,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(test_buffer_server test/test_buffer_server.cpp) + ament_add_ros_isolated_gtest(test_buffer_server test/test_buffer_server.cpp) target_link_libraries(test_buffer_server ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -166,7 +166,7 @@ if(BUILD_TESTING) # tf2_msgs::tf2_msgs ) - ament_add_gtest(test_buffer_client test/test_buffer_client.cpp) + ament_add_ros_isolated_gtest(test_buffer_client test/test_buffer_client.cpp) target_link_libraries(test_buffer_client ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -178,7 +178,7 @@ if(BUILD_TESTING) # Adds a tf2_ros message_filter unittest that uses # multiple target frames and a non-zero time tolerance - ament_add_gtest(${PROJECT_NAME}_test_message_filter test/message_filter_test.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_message_filter test/message_filter_test.cpp) target_link_libraries(${PROJECT_NAME}_test_message_filter ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -188,7 +188,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_transform_listener test/test_transform_listener.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_transform_listener test/test_transform_listener.cpp) target_link_libraries(${PROJECT_NAME}_test_transform_listener ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -196,7 +196,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_static_transform_broadcaster test/test_static_transform_broadcaster.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_static_transform_broadcaster test/test_static_transform_broadcaster.cpp) target_link_libraries(${PROJECT_NAME}_test_static_transform_broadcaster ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -204,7 +204,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_transform_broadcaster test/test_transform_broadcaster.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_transform_broadcaster test/test_transform_broadcaster.cpp) target_link_libraries(${PROJECT_NAME}_test_transform_broadcaster ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -212,7 +212,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_time_reset test/time_reset_test.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_time_reset test/time_reset_test.cpp) target_link_libraries(${PROJECT_NAME}_test_time_reset ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -222,7 +222,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_velocity test/velocity_test.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_velocity test/velocity_test.cpp) target_link_libraries(${PROJECT_NAME}_test_velocity ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} @@ -231,7 +231,7 @@ if(BUILD_TESTING) # rclcpp::rclcpp ) - ament_add_gtest(${PROJECT_NAME}_test_listener test/listener_unittest.cpp) + ament_add_ros_isolated_gtest(${PROJECT_NAME}_test_listener test/listener_unittest.cpp) target_link_libraries(${PROJECT_NAME}_test_listener ament_cmake_ros_core::ament_ros_defaults ${PROJECT_NAME} diff --git a/tf2_ros/package.xml b/tf2_ros/package.xml index 7371b7e18..9048017d9 100644 --- a/tf2_ros/package.xml +++ b/tf2_ros/package.xml @@ -30,7 +30,7 @@ tf2 tf2_msgs - ament_cmake_gtest + ament_cmake_ros ament_lint_auto ament_lint_common rosgraph_msgs diff --git a/tf2_ros_py/conftest.py b/tf2_ros_py/conftest.py new file mode 100644 index 000000000..5cc3480bf --- /dev/null +++ b/tf2_ros_py/conftest.py @@ -0,0 +1,25 @@ +# Copyright 2026 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +from rmw_test_fixture_implementation import rmw_test_isolation_start +from rmw_test_fixture_implementation import rmw_test_isolation_stop + + +@pytest.fixture(autouse=True, scope='session') +def rmw_isolation(): + """Start RMW isolation before any ROS context is created.""" + rmw_test_isolation_start() + yield + rmw_test_isolation_stop() diff --git a/tf2_ros_py/package.xml b/tf2_ros_py/package.xml index bbd6484d6..d3b78c220 100644 --- a/tf2_ros_py/package.xml +++ b/tf2_ros_py/package.xml @@ -27,6 +27,7 @@ ament_pep257 ament_xmllint python3-pytest + rmw_test_fixture_implementation ament_python