unittest support: Coroutine was never awaited
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- testing-qa
調査の方向性
issue に示されている pytest.mark.asyncio でマークされた async テストと data_svc_fixture、event_loop fixture から始めます。get_data と execute_query_async の各呼び出しを追跡し、その後テストを実行して coroutine が await されていない理由を特定します。警告がなくなり、assertion が通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
I am trying to create a test case for the below async function get_data. I get Runtime warning as RuntimeWarning: coroutine 'TestAsyncStatSvc.test_async_get_data' was never awaited
testfunction(**testargs)
Below is my code. Please guide on this one. AFAIK, we get this exception when there is no event loop so I created one in the fixture. What is there that I am missing?
async def get_data(self, data_id=None):
sql = """
SELECT id, description
FROM data_table
"""
sql_params = []
if data_id:
sql += """
WHERE id = $1
"""
sql_params += [data_id]
result = await self.dbproxy_async.execute_query_async(sql, sql_params)
if result.empty and data_id:
raise NotFound('data %s not found.' % data_id)
return result.to_json()
Below Is the test case:
class TestAsyncStatSvc(object):
TEST_DATA = {
'Key1': ['Key1', 'Data desc for key1'],
'Key2': ['Key2', 'Data desc for key2'],
None: [
['Key1', 'Data desc for key1'],
['Key2', 'Data desc for key2']
]
}
@pytest.mark.asyncio
async def test_async_get_data(self, data_svc_fixture):
for query_value in TESTDATA.keys:
execute_stub = MagicMock(return_value=self.TESTDATA[query_value])
# Wrap the stub in a coroutine (so it can be awaited)
execute_coro = asyncio.coroutine(execute_stub)
# Stub the database db_proxy
db_proxy = MagicMock()
db_proxy.execute_query_async = execute_coro
result = data_svc_fixture.get_data(data_id=query_value)
assert result == self.TESTDATA[query_value]
if query_value is not None:
assert len(comm) == 1
else:
assert len(comm) == 2
with pytest.raises(NotFound):
data_svc_fixture.get_data('Unobtained')
And here are the fixtures:
class Context:
def __init__(self, loop, svc_fixture):
self.loop = loop
self.svc_fixture = svc_fixture
@pytest.yield_fixture(scope="function")
def data_svc_fixture(db_proxy_fixture, get_service_fixture, my_svc_configurator_fixture, event_loop):
ctx = Context(event_loop, get_service_fixture('MySvc'))
yield ctx
event_loop.run_until_complete(asyncio.gather(*asyncio.Task.all_tasks(event_loop), return_exceptions=True))
@pytest.yield_fixture()
def event_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()
- 主要言語
- Python
- スター
- 1.7k
- フォーク
- 209
- 平均マージ
- 1時間 51分
- マージ済み PR(30日)
- 13
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytest-dev/pytest-asyncio のほかの issue
-
Turn deprecation of the "scope" keyword argument of the asyncio marker into an error対応中かも @mokashang が 119 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
pytest-dev/pytest-asyncio#1475 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
pytest-dev/pytest-asyncio#1514 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Loop factory parametrization tears down async fixtures used by sync tests対応中かも @TLNing260310 が 47 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
pytest-dev/pytest-asyncio#1501 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
`pytest_asyncio_loop_factories` hook is not called when `pytest.mark.asyncio` is added via parametrization再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
pytest-dev/pytest-asyncio#1463 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Don't warn about `asyncio_default_fixture_loop_scope` unless the test suite uses `pytest-asyncio`再び着手できるかも @DawnofGenX が 11 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
pytest-dev/pytest-asyncio#1344 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
pytest-dev/pytest-asyncio の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
TomerAberbach/profiler-md#733 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
its-me-prash/vwgroup-connect-ha#1858 ·
メンテナーはふだん 1 日以内に返信
-
area: client bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
Deleting all alarms or timers shows deleted ones until the next update when there are none leftオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
leikoilja/ha-google-home#1107 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Graphify-Labs/graphify#4524 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信