ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

unexpected keyword argument 'package' from launch_testing

asked 2021-10-27 09:17:08 -0500

msmcconnell gravatar image

I am trying to use launch_testing to create integration tests for my ROS2 node. However, I keep getting the following error:

run_test.py: invoking following command in '/workspaces/carma_ws/temp_ws/build/system_controller/test':
 - /usr/bin/python3 -m launch_testing.launch_test /workspaces/carma_ws/temp_ws/carma-platform/system_controller/test/launch_test.py --junit-xml=/workspaces/carma_ws/temp_ws/build/system_controller/test_results/system_controller/launch_test.xunit.xml --package-name=system_controller
usage: launch_test.py [-h] [--package-name PACKAGE_NAME] [-v] [-s]
                      [--junit-xml XMLPATH]
                      launch_test_file
                      [launch_arguments [launch_arguments ...]]
launch_test.py: error: __init__() got an unexpected keyword argument 'package'
-- run_test.py: return code 2

I have added my launch test to my CMakeLists.txt file with

add_launch_test(
  launch_test.py
)

And the test itself looks like this

import os
import sys

import launch
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch_ros.actions import Node
import launch_testing
import pytest
import unittest

import rclpy
from rclpy.node import Node

from carma_msgs.msg import SystemAlert

@pytest.mark.launch_test
def generate_test_description():

    return launch.LaunchDescription([
        Node( # Managed node 1
            package='carma_ros2_utils',
            executable='test_carma_lifecycle_node',
            name='test_carma_lifecycle_node_1',
            output='screen',
            ),
        Node( # Managed node 2
            package='carma_ros2_utils',
            executable='test_carma_lifecycle_node',
            name='test_carma_lifecycle_node_2',
            output='screen',
            ),
        Node( # System Controller to test
            package='carma_ros2_utils',
            executable='system_controller',
            name='test_system_controller',
            output='screen',
            parameters=[{
                'signal_configure_delay': 5, 
                'service_timeout_ms': 5000,
                'call_timeout_ms': 5000,
                'required_subsystem_nodes': ['test_carma_lifecycle_node_1', 'test_carma_lifecycle_node_2']}],
            ),

        # We can start this test right away as there is nothing else to wait on
        launch_testing.actions.ReadyToTest()
    ])


# All tests in this class will run  in parallel
class TestRuntime(unittest.TestCase):

    def test_nominal_lifecycle(self, proc_output):
        # This will match stdout from any process.  In this example there is only one process
        # running

        # Check that the system controller is starting up
        proc_output.assertWaitFor('Initializing SystemControllerNode', proc='system_controller', strict_proc_matching=True, timeout=1, stream='stdout')
        proc_output.assertWaitFor('Attempting to configure system...', proc='system_controller', strict_proc_matching=True, timeout=6, stream='stdout')

        # Check that the system controller has driven the lifecycle of the nodes to active state
        proc_output.assertWaitFor('test_carma_lifecycle_node_1 node is Configured!', proc='test_carma_lifecycle_node_1', strict_proc_matching=True, timeout=10, stream='stdout')
        proc_output.assertWaitFor('test_carma_lifecycle_node_2 node is Configured!', proc='test_carma_lifecycle_node_2', strict_proc_matching=True, timeout=10, stream='stdout')
        proc_output.assertWaitFor('test_carma_lifecycle_node_1 node is Activated!', proc='test_carma_lifecycle_node_1', strict_proc_matching=True, timeout=5, stream='stdout')
        proc_output.assertWaitFor('test_carma_lifecycle_node_2 node is Activated!', proc='test_carma_lifecycle_node_2', strict_proc_matching=True, timeout=5, stream='stdout')




# All tests in this class will run on shutdown
@launch_testing.post_shutdown_test()
class TestPostShutdown(unittest.TestCase):

    def test_exit_code(self, proc_info):
        # Check that all processes in the launch (in this case, there's just one) exit
        # with code 0
        launch_testing.asserts.assertExitCodes(proc_info, allowable_exit_codes=[0])

Does anyone know what the source of this error is? How do I allow the test to accept the package argument?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-10-27 16:08:06 -0500

msmcconnell gravatar image

updated 2021-10-27 16:08:25 -0500

Turns out this was caused by a name conflict. I had both

from rclpy.node import Node

and

from launch_ros.actions import Node

which caused a conflict on my node launch

Node( # Managed node 1
            package='carma_ros2_utils',
            executable='test_carma_lifecycle_node',
            name='test_carma_lifecycle_node_1',
            output='screen',
            ),

Corrected by changing to

launch_ros.actions.Node( # Managed node 1
            package='carma_ros2_utils',
            executable='test_carma_lifecycle_node',
            name='test_carma_lifecycle_node_1',
            output='screen',
            ),
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-10-27 09:17:08 -0500

Seen: 364 times

Last updated: Oct 27 '21