From 4a3916aec7017fd9c3999cf179bd4cadb48ced19 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 5 May 2026 20:45:53 -0400 Subject: [PATCH] Fix launch_testing_ros so it works with pytest 7. (#543) We need this compatibility because Windows pixi is still using an older pytest. This doesn't really hurt anything either. While we are in here, fix a pep257 warning that I noticed in the tests. Signed-off-by: Chris Lalancette (cherry picked from commit 1c0a7ae2f1e513111278147e703eb9ce33a652a6) # Conflicts: # launch_testing_ros/launch_testing_ros_pytest_entrypoint.py --- .../launch_testing_ros_pytest_entrypoint.py | 10 ++++++++++ .../test/examples/check_msgs_launch_test.py | 7 ++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/launch_testing_ros/launch_testing_ros_pytest_entrypoint.py b/launch_testing_ros/launch_testing_ros_pytest_entrypoint.py index 20f9d8b23..fa0d3c55f 100644 --- a/launch_testing_ros/launch_testing_ros_pytest_entrypoint.py +++ b/launch_testing_ros/launch_testing_ros_pytest_entrypoint.py @@ -17,6 +17,8 @@ # importing downstream modules in upstream packages when built with a merged # workspace. +import pathlib + import pytest @@ -24,7 +26,15 @@ def pytest_launch_collect_makemodule(path, parent, entrypoint): marks = getattr(entrypoint, 'pytestmark', []) if marks and any(m.name == 'rostest' for m in marks): from launch_testing_ros.pytest.hooks import LaunchROSTestModule +<<<<<<< HEAD module = LaunchROSTestModule.from_parent(parent=parent, fspath=path) +======= + if _pytest_version_ge(7): + path = pathlib.Path(module_path) + module = LaunchROSTestModule.from_parent(parent=parent, path=path) + else: + module = LaunchROSTestModule.from_parent(parent=parent, fspath=module_path) +>>>>>>> 1c0a7ae (Fix launch_testing_ros so it works with pytest 7. (#543)) for mark in marks: decorator = getattr(pytest.mark, mark.name) decorator = decorator.with_args(*mark.args, **mark.kwargs) diff --git a/launch_testing_ros/test/examples/check_msgs_launch_test.py b/launch_testing_ros/test/examples/check_msgs_launch_test.py index ce2964427..20100012a 100644 --- a/launch_testing_ros/test/examples/check_msgs_launch_test.py +++ b/launch_testing_ros/test/examples/check_msgs_launch_test.py @@ -55,11 +55,8 @@ def subscription_callback(self, data: String): self.msg_event_object.set() def spin(self): - try: - while rclpy.ok() and not self.spinning.is_set(): - rclpy.spin_once(self.node, timeout_sec=0.1) - finally: - return + while rclpy.ok() and not self.spinning.is_set(): + rclpy.spin_once(self.node, timeout_sec=0.1) def setUp(self): rclpy.init()