Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PatrickSowinski opened this issue Sep 12, 2023 · 1 comment

Comments

@PatrickSowinski
Copy link

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.

@JustusBraun
Copy link

Did you find a solution? I am having the same problem. I have a fixture which launches a Node which then crashes. When the Node crashes the Testcase just hangs indefinitely. The README says that Test can fail if a Node dies unexpectedly, is there an argument that needs to be passed to enable this behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants