mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-36996: Handle async functions when mock.patch is used as a decorator (GH-13562)
Return a coroutine while patching async functions with a decorator. Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> https://bugs.python.org/issue36996
This commit is contained in:
parent
71dc7c5fbd
commit
436c2b0d67
3 changed files with 73 additions and 26 deletions
|
@ -66,6 +66,14 @@ class AsyncPatchDecoratorTest(unittest.TestCase):
|
|||
|
||||
test_async()
|
||||
|
||||
def test_async_def_patch(self):
|
||||
@patch(f"{__name__}.async_func", AsyncMock())
|
||||
async def test_async():
|
||||
self.assertIsInstance(async_func, AsyncMock)
|
||||
|
||||
asyncio.run(test_async())
|
||||
self.assertTrue(inspect.iscoroutinefunction(async_func))
|
||||
|
||||
|
||||
class AsyncPatchCMTest(unittest.TestCase):
|
||||
def test_is_async_function_cm(self):
|
||||
|
@ -91,6 +99,14 @@ class AsyncPatchCMTest(unittest.TestCase):
|
|||
|
||||
test_async()
|
||||
|
||||
def test_async_def_cm(self):
|
||||
async def test_async():
|
||||
with patch(f"{__name__}.async_func", AsyncMock()):
|
||||
self.assertIsInstance(async_func, AsyncMock)
|
||||
self.assertTrue(inspect.iscoroutinefunction(async_func))
|
||||
|
||||
asyncio.run(test_async())
|
||||
|
||||
|
||||
class AsyncMockTest(unittest.TestCase):
|
||||
def test_iscoroutinefunction_default(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue