Add helpers to launch_pytest for checking stdout and stderr of launched processes
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 155
- フォーク
- 182
- 平均マージ
- 2日 14時間
- マージ済み PR(30日)
- 6
説明
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!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 でプロセスの stdout と stderr をどのように監視できるかを調査します。Gazebo のネストした launch のケースも含めます。完了時には、期待される出力とエラーをカバーするテスト付きで、ドキュメント化されたヘルパーまたは fixture を提供する必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100