1

Im having a headache trying to test this code

 pool = await session_pool()
 async with pool.acquire() as conn:
       async with conn.cursor() as cursor:
                res = await cursor.execute(sql)

                rows = res.fetchall()

                return rows

I only need to patch the functions session_pool, acquire, cursor and execute, and force the return of fetchall to verify the function. Thanks!

This is the test that i build

class TestClass(unittest.TestCase):
    def test_funtion(self):
        with patch('some_direction.session_pool') as mock_pool:
            result = asyncio.run(ClosingFunds.find(some_values))

And the output says

>               res = await cursor.execute(sql)
E               TypeError: object MagicMock can't be used in 'await' expression

0 Answers0