Add helpers to launch_pytest for checking stdout and stderr of launched processes
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先比较 launch_pytest/test/launch_pytest/examples/pytest_hello_world.py 与 launch_testing/asserts/assert_output.py 和 launch_testing/event_handlers/stdout_ready_listener.py。调查当测试不持有进程操作时,launch_pytest 如何观察进程的标准输出和标准错误,包括 Gazebo 嵌套 launch 的情况。完成后应提供有文档说明的辅助工具或 fixtures,并通过测试覆盖预期的输出和错误。
由索引模型根据 Issue 内容生成。
描述
Feature request
Feature description
launch_testing provides several utilities for checking and waiting on process output, e.g.
It would be nice if we had similar facilities with launch_pytest.
We do have an example of checking the output of a process:
but it requires that the test has a reference to the action under test and that they can set the cached_output=True argument:
As a concrete example, I recently wanted to confirm that launching Gazebo Classic from a nested launch description would produce some expected output and no errors, however we don't have access to the process actions. Here's the existing test where are including the Gazebo launch description to test:
I did not find a simple way to check the output in this case, but maybe I've overlooked something.
Ultimately, I was able to write the test I wanted by registering a launch event handler on process IO and storing that in a list that can be checked in the test. Here's a test fixture I wrote that can be used by tests to check output on stderr:
@pytest.fixture()
def launch_capture_io():
class LaunchCaptureIO:
def __init__(self):
self._event = Event()
self.stderr = []
self.action = RegisterEventHandler(OnProcessIO(on_stderr=self._on_stderr))
def _on_stderr(self, io):
self.stderr.append(io.text.decode('utf-8'))
self._event.set()
def wait_for_stderr(self, *, timeout) -> bool:
result = self._event.wait(timeout)
self._event.clear()
return result
return LaunchCaptureIO()
Implementation considerations
Some options that might be worth investigating (I haven't thought too much about them yet):
- It would be nice if we could leverage any existing pytest features for io handling. I tried to use the built-in capsys feature, but I wasn't able to get it to work (I suspect this is due to launch creating child processes).
- Add a fixture like the one I presented above for the Gazebo test case (ie. use launch events to record process io).
- Instrument launch to be more amenable to testing process io. If we could easily identify processes of interest (e.g we have process matchers for events already) and configure them to cache their output from the test (e.g. maybe a launch configuration), then we could add helpers to query process io.
If anyone has other ideas or thoughts, happy to hear them!
- 主要语言
- Python
- 星标
- 156
- 派生
- 200
- 平均合并
- 2 天 11 小时
- 30 天内合并 PR
- 11
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ros2/launch 的其他 Issue
-
Use a relative target for the `latest` log symlink so it survives different absolute mount paths (host/Docker)可能已有人在做 @Old-Ding 于 139 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
ros2/launch#978 · 1 个 reaction ·
维护者通常 1 天内回复
-
Add OpaqueFunction to list at docs.ros.org可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug help wanted
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 30/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 1 天内回复
-
[launch_testing] pytest>8.1 dropped the legacy "path" argument from its internal hooks on humble可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 3/5 1-2 天 新手友好度 55/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
hive size:simple
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 1/5 1 小时以内 新手友好度 90/100
-
backend enhancement priority:P3
难度 2/5 1-3 小时 新手友好度 68/100
geolens-io/geolens#4161 ·
维护者通常 1 天内回复