ros2 / ros2/launch

`launch_pytest` Test does not terminate if an error occurs in launch fixture

Open
#732 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
155
Forks
182
Avg merge
2d 14h
Merged PRs (30d)
6

Description

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • binaries (using apt-get install ros-humble-launch-pytest)
  • Version or commit hash:
    • humble (1.0.4 ?)
  • DDS implementation:
    • no idea, how do I find this?
  • Client library (if applicable):
    • rclpy + pytest + launch_pytest
Steps to reproduce issue

Have any launch-related runtime error in your launch_pytest.fixture. If any test uses this fixture, it will get stuck because the fixture fails and the test never starts. If you run pytest verbosely with -s, it will print the error from the fixture and then run indefinitely.

Example code that will cause this indefinite running:

import launch_pytest
import pytest
import rclpy.node
from ament_index_python.packages import get_package_share_directory
from launch.actions import IncludeLaunchDescription
from launch.launch_description import LaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import PathJoinSubstitution


# A launch fixture with an error (can be any error that happens at runtime on the LaunchDescription level)
# (not a Python error)
# (In this case we use a launch file path that does not exist)
@launch_pytest.fixture
def launch_description() -> LaunchDescription:
    package_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            PathJoinSubstitution(
                [
                    get_package_share_directory("package_name"),
                    "thisIsAWrongPathThatWillLeadToNoSuchFileAndThrowAnError",
                    "package.launch.py",
                ]
            )
        )
    )
    return LaunchDescription(
        [
            package_launch,
            launch_pytest.actions.ReadyToTest(),
        ]
    )


# test that uses the failing fixture
@pytest.mark.launch(fixture=launch_description)
def test_anything() -> None:
    rclpy.init()
    try:
        # does not matter what we do here, the test will get stuck setting up the fixture before this
        assert True
    finally:
        rclpy.shutdown()
Expected behavior

Error from fixture setup leads to test failing.

Actual behavior

Fixture error is printed, when pytest is run with -s, but the test keeps running indefinitely, unless terminated from the outside by an interrupt or by using an external tool like pytest-timeout.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the launch_pytest.fixture setup used by the @pytest.mark.launch(fixture=launch_description) test and reproduce the failure with the provided missing launch-file example. Check how the fixture reports runtime errors and terminates, then verify that pytest fails promptly instead of hanging and that normal launch_pytest tests still complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.