Patched async function not registering calls until coroutine is awaited
オープン
まだ誰も着手していません。
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
When using autospec=True the patched async function only has calls registered after the coroutine is awaited. This behavior started happening after I upgraded from 3.12 to 3.13.6.
Code to reproduce
File tests/other_module.py
async def a(value):
return value * 2
File tests/test_1.py
from unittest.mock import patch
import pytest
import other_module
pytestmark = pytest.mark.asyncio(loop_scope="session")
def b(value):
return other_module.a(value)
async def test_1():
with patch.object(other_module, "a", side_effect=other_module.a, autospec=True) as a_mock:
result = b(10)
assert not a_mock.called # This should be True because 'a' was called, but it's False
await result
assert a_mock.called # Now it's True
CPython versions tested on:
3.13
Operating systems tested on:
Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
tests/other_module.py と tests/test_1.py を使って動作を再現し、side_effect と autospec=True を指定した patch.object に注目してください。mock が coroutine の作成および await に対してどの時点で呼び出しを記録するかを確認してください。最初のアサーションが await より前に成功し、その動作が適切な CPython テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100