Search code examples
pythonpython-unittestpython-asynciopeeweeaiohttp

How to test aiohttp and peewee-async?


I wanna run 2 asynchronous tests for my database class with aiohttp and peewee-async.

@unittest_run_loop
async def test_create_instance(self):
    instance = await self.model.create_instance({})
    self.assertTrue(isinstance(instance, dict))
    self.assertTrue(instance is not None)

@unittest_run_loop
async def test_retrieve_instance(self):
    instance = await self.model.create_instance({})
    retrieved = await self.model.retrieve_instance(int(instance['id']))
    self.assertTrue(instance == retrieved)

But I give just

peewee.ProgrammingError: close cannot be used while an asynchronous query is underway

Thanks you for your attention!


Solution

  • The actual solution I pushed to my repo.
    You can watch it here:
    https://github.com/dennypenta/aiohttp-peewee

    Feed free to star my repo, create issue and ask any questions.

    My twitter: @denny_penta