inspect.getcoroutinefunction() can break testing with unittest.mock.patch() #14021
Answered
by
injae-kim
secrett2633
asked this question in
Questions
-
First Check
Commit to Help
Example Codeimport sys
import asyncio
import inspect
from unittest.mock import create_autospec, patch
print(f"Python version: {sys.version_info[:2]}") # (3, 12)
async def foo():
pass
mock_autospec = create_autospec(foo)
print(asyncio.iscoroutinefunction(mock_autospec)) # True
print(inspect.iscoroutinefunction(mock_autospec)) # False
with patch('__main__.foo', autospec=True) as mock_foo:
print(asyncio.iscoroutinefunction(mock_foo)) # True
print(inspect.iscoroutinefunction(mock_foo)) # FalseDescriptionThis issue is related to a known Python bug that was fixed in Python 3.13 but has not been backported to earlier versions: python/cpython#94924 Operating SystemWindows Operating System DetailsNo response FastAPI Version0.116.1 Pydantic Version2.10.6 Python VersionPython 3.11.3 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
injae-kim
Aug 30, 2025
Replies: 1 comment
-
|
Fix PR: #14022 👍 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
secrett2633
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix PR: #14022 👍