8000 bpo-37047: Refactor AsyncMock setup logic for autospeccing by tirkarthi · Pull Request #13574 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37047: Refactor AsyncMock setup logic for autospeccing #13574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 27, 2019
Prev Previous commit
Next Next commit
Rename async_func_1 to async_func_args
  • Loading branch information
tirkarthi committed May 25, 2019
commit f5742d7ef0c5d21427a5d156e87b87cfce2843fe
8 changes: 5 additions & 3 deletions Lib/unittest/test/testmock/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def normal_method(self):
async def async_func():
pass

async def async_func_1(a, b, *, c):
async def async_func_args(a, b, *, c):
pass

def normal_func():
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_create_autospec_instance(self):
create_autospec(async_func, instance=True)

def test_create_autospec(self):
spec = create_autospec(async_func_1)
spec = create_autospec(async_func_args)
awaitable = spec(1, 2, c=3)
async def main():
await awaitable
Expand Down Expand Up @@ -253,13 +253,15 @@ def test_async_attributes_coroutines(MockNormalClass):
def test_patch_with_autospec(self):

async def test_async():
with patch(f"{__name__}.async_func_1", autospec=True) as mock_method:
with patch(f"{__name__}.async_func_args", autospec=True) as mock_method:
awaitable = mock_method(1, 2, c=3)
self.assertIsInstance(mock_method.mock, AsyncMock)

self.assertTrue(asyncio.iscoroutinefunction(mock_method))
self.assertTrue(asyncio.iscoroutine(awaitable))
self.assertTrue(inspect.isawaitable(awaitable))

# Verify the default values during mock setup
self.assertEqual(mock_method.await_count, 0)
self.assertEqual(mock_method.await_args_list, [])
self.assertIsNone(mock_method.await_args)
Expand Down
0