Python: Test that a coroutine has been closed?

Viewed 30

I have a function like this:

async def my_func:
    try:
        rv = await some_other_func()
        raise Exception()
     except Exception:
        rv.close()

test:

   @pytest.mark.asyncio
   async def test_close()
        with mock.patch("module.some_other_func") as f:
            await my_func()
            f.close.assert_called_once()

I would like to test that my awaitable is closed in case of an exception. Unfortunately, the coroutine never registers in the MagiCmock object. Any ideas how to test?

0 Answers
Related