0
내가 플러그인 asyncio pytest 다음과 같은 방법을 테스트하기 위해 노력하고 제기 파이썬 :는 테스트 asyncio 코 루틴 pytest-asyncio 플러그인은 형식 오류
class Controller(object):
async def get_item(self, item_id):
item = await self.item_collection.find_one({'item_id': item_id})
return item
을 그리고 난 다음의 시험을 서면으로 작성했습니다 :
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'
을 내가
item = await self.item_collection.find_one({'item_id': item_id})
테스트 페이지에 await를 제거하면
item = await self.item_collection.find_one({'item_id': item_id})
TypeError: object dict can't be used in 'await' expression
:
이 테스트는 다음과 같은 오류가 발생합니다 엉덩이,하지만 어떻게 내가이 방법을 테스트에 갈 수 있습니까?
'find_one'을 조롱하고 있습니까? – dirn
안녕하세요 @dirn, 나는 차례로 MongoMock을 사용하는 json 설비와 pytest-mongodb 플러그인을 사용하고 있습니다. mocked mongo 콜렉션이 예상대로 작동합니다. 미안합니다. –
MongoMock이 asyncio를 이해하는 것처럼 보이지 않습니다. 그것은 코 루틴이 아닌 일반적인 방법을 가진 콜렉션을 정의합니다. 어떤 운전자를 사용하고 있습니까? 모터? 아마도 그것을 조롱하거나 직접 처리 할 수있는 라이브러리를 찾아야 할 것입니다. – dirn