Skip to content
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

support async function calls #139

Open
BugDiver opened this issue Mar 22, 2022 · 0 comments
Open

support async function calls #139

BugDiver opened this issue Mar 22, 2022 · 0 comments

Comments

@BugDiver
Copy link

Currently I'm having issues testing my async methods in notebook.
Exmaple:
Notebook:

import httpx


async make_api_call(client, url, headers, body)
    res = await client.post(url, headers=headers, json=body)
    if res.status_code == 200:
        return res.json()
    else:
        print(res)


if __name__ == '__main__'
    with httpx.AsyncClient() as client:
        await make_api_call(cleint, url,... ..)

TestCase:

import unittest
from unittest.mock import MagicMock

class TestAPI(unittest.IsolatedAsyncioTestCase):
    async def test_api_call(self):
        with testbook(notebook_path, execute=True) as nb:
            make_api_call = nb.ref('make_api_call')
            cleint = MagicMock()
            await make_api_call(client,url, ...)
            client.post.assert_called()

Is there any way to test async function calls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant