ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
126 stars 141 forks source link

[launch_pytest] node outputting to stderr instead of stdout is confusing #619

Closed LoicFerrot closed 2 years ago

LoicFerrot commented 2 years ago

Bug report / question

Steps to reproduce issue

copy-paste the following in test_confusing.py, then run pytest test_confusing.py

import launch
import launch_pytest
import launch_ros
import pytest

@pytest.fixture
def foo_node_process() -> launch.actions.ExecuteProcess:
  return launch_ros.actions.Node(
      package='examples_rclpy_minimal_client', executable='client', name='client', output='screen', cached_output=True
  )

@launch_pytest.fixture
def foo_launch_description(foo_node_process) -> launch.LaunchDescription:
  return launch.LaunchDescription([foo_node_process])

@pytest.mark.launch(fixture=foo_launch_description)
def test_read_foo_stdout(foo_node_process, launch_context):
  assert launch_pytest.tools.wait_for_start_sync(launch_context, foo_node_process, timeout=5)

  def validate_output(output: str):
    assert len(output) > 0, 'Output is empty'

  # passes
  launch_pytest.tools.assert_stderr_sync(launch_context, foo_node_process, validate_output, timeout=5)
  # fails
  launch_pytest.tools.assert_output_sync(launch_context, foo_node_process, validate_output, timeout=5)

Expected behavior

The output of the launched node (logging info messages "service not available, waiting again...") should be in stdout.

Actual behavior

The output is in stderr, causing a confusing fail of the test.

Additional information

I am a bit confused by the output='screen' argument and the fact that the pytest_hello_world.py is using assert_output_sync. However, it is maybe intended behavior, as running ros2 run examples_rclpy_minimal_client client also outputs to stderr. Is it normal? Could you help me understand?

Thanks!

clalancette commented 2 years ago

This is intended behavior. But I'd rather answer this over on https://answers.ros.org, which is our central Question and Answer site. So I'm going to close this, and ask you to please reopen the question over there and tag me (@clalancette). Once I see that, I'll give the more detailed answer.

LoicFerrot commented 2 years ago

All right, I just opened a question on ROS answers. Thanks for your help!