-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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 * 2File 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 TrueCPython versions tested on:
3.13
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Todo