I am trying to test the following method with the pytest asyncio plugin:
class Controller(object):
async def get_item(self, item_id):
item = await self.item_collection.find_one({'item_id': item_id})
return item
And I've written the following test:
class TestController(object):
@pytest.mark.asyncio
async def test_get_item(self):
controller = Controller()
item = await controller.get_item('item-1')
assert item.get('item_id') == 'item-1'
This test raises the following error:
item = await self.item_collection.find_one({'item_id': item_id})
TypeError: object dict can't be used in 'await' expression
If I remove the await in item = await self.item_collection.find_one({'item_id': item_id}) the test passes, but how can I go about testing this method as it is?
Aucun commentaire:
Enregistrer un commentaire