Add pytest fixture to clean up the IO loop

オープン
#471 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
testing-qa

調査の方向性

Start by locating the streamz unit tests and the existing pristine_loop fixture. Compare that fixture with the proposed loop_cleaner cleanup, then run the affected tests to reproduce the running-event-loop error. Done means the tests leave no running or open global asyncio event loop and pass reliably with the jupyter_core change described.

索引モデルが issue の本文から書いたものです。

説明

I recently came across this error in my unit tests:

RuntimeError: This event loop is already running

The error doesn't come from streamz, it's from jupyter_core, in this recent change.

But it is triggered because my streamz tests don't clean up properly after them selves.
They leave the global async event loop, asyncio.get_event_loop(), in a running state.

To fix it I had to add this fixture to my unit tests:

@pytest.fixture(autouse=True)
def loop_cleaner():
    yield None
    close_io_loop()


def close_io_loop():

    IOLoop().current().stop()
    IOLoop().current().close()
    assert not asyncio.get_event_loop().is_running()
    asyncio.get_event_loop().close()
    assert asyncio.get_event_loop().is_closed()
    asyncio.set_event_loop(None)

It's a bit similar to the existing pristine_loop, but doesn't exactly do the same thing (afaict).

I hope this can help any one having similar issues.

主要言語
Python
スター
1.3k
フォーク
149
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-streamz/streamz のほかの issue

python-streamz/streamz の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。