월 15,400원
5개월 할부 시다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결배달앱은 어떻게 내 주변의 맛집을 찾을까?
odm 관련
혹시 강사님께서 beanie와 같은 odm 라이브러리를 사용하지 않고, motor 드라이브와 data class로 구현한 이유가 궁금합니다.추가적으로 entity를 pydantic model이 아닌 data class로 구현하신 이유가 궁금해요
- 미해결배달앱은 어떻게 내 주변의 맛집을 찾을까?
test.sh 파일 실행 후 에러 처리 방법
질문하실 땐 https://gist.github.com/ 를 사용하시면 코드를 쉽게 공유할 수 있습니다!원하고자 하는 것실제 작성한 코드실행한 결과원하는 결과이렇게 4가지를 꼭 적어주셔야 도와드릴 수 있습니다 :) 처음 프로젝트를 실행 후 test.sh 파일을 실행했는데에러가 두개 발생했습니다.에러 처리는 어떻게 하나요?제 에러는 첨부한 사진과 같습니다.파이썬(3.11.3), poetry(1.4.2) 모두 강의에 나온 버전 설치했습니다.
- 해결됨배달앱은 어떻게 내 주변의 맛집을 찾을까?
테스트를 실행했을 때 RuntimeError: Event loop is closed 에러가 발생합니다.
질문하실 땐 https://gist.github.com/ 를 사용하시면 코드를 쉽게 공유할 수 있습니다!원하고자 하는 것실제 작성한 코드실행한 결과원하는 결과 이렇게 4가지를 꼭 적어주셔야 도와드릴 수 있습니다 :) test_shop_insert_one() 함수를 추가하여 테스트를 실행했을 때 RuntimeError: Event loop is closed 에러가 발생하여 테스트가 실패합니다. app/tests/entities/collections/shop/test_shop_collection.py F [100%] ============================================================================= FAILURES ============================================================================= _______________________________________________________________________ test_shop_insert_one _______________________________________________________________________ @pytest.mark.asyncio async def test_shop_insert_one() -> None: # Given name = "치킨집" category_codes = [CategoryCode.CHICKEN] delivery_areas = [ ShopDeliveryAreaSubDocument( poly=GeoJsonPolygon(coordinates=[[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]]), ) ] # When > shop = await ShopCollection.insert_one(name, category_codes, delivery_areas) app/tests/entities/collections/shop/test_shop_collection.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ app/entities/collections/shop/shop_collection.py:20: in insert_one result = await cls._collection.insert_one( /PATH/OF/POETRY/CACHE/lib/python3.11/site-packages/motor/metaprogramming.py:73: in method return framework.run_on_executor( /PATH/OF/POETRY/CACHE/lib/python3.11/site-packages/motor/frameworks/asyncio/__init__.py:85: in run_on_executor return loop.run_in_executor(_EXECUTOR, functools.partial(fn, *args, **kwargs)) /PATH/OF/PYTHON/lib/python3.11/asyncio/base_events.py:816: in run_in_executor self._check_closed() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_UnixSelectorEventLoop running=False closed=True debug=False> def _check_closed(self): if self._closed: > raise RuntimeError('Event loop is closed') E RuntimeError: Event loop is closed /PATH/OF/PYTHON/lib/python3.11/asyncio/base_events.py:519: RuntimeError ===================================================================== short test summary info ====================================================================== FAILED app/tests/entities/collections/shop/test_shop_collection.py::test_shop_insert_one - RuntimeError: Event loop is closed =================================================================== 1 failed, 1 passed in 0.55s ====================================================================에러로그는 위와 같습니다. --async-mode 를 test로 변경해보면 저 단계까지 가기 전에 에러가 발생하고@pytest.mark.asyncio 어노테이션을 추가해줘도 결과는 같습니다.poetry 를 이용한 환경 구성이 처음이라 해당 지식이 많이 부족하여 이 문제를 어떻게 해결해야하는지 잘 모르겠습니다. 파이썬 버전은 3.11.3poetry 버전은 1.4.2mongodb 버전은 6.0.11 입니다. [tool.poetry.dependencies] fastapi = "^0.95.2" gunicorn = "^20.1.0" httpx = "^0.24.1" motor = "^3.1.2" orjson = "^3.8.14" python = "^3.11" uvicorn = "^0.22.0" [tool.poetry.group.dev.dependencies] black = {extras = ["d"], version = "^23.3.0"} coverage = "^7.2.3" isort = "^5.12.0" mypy = "^1.3.0" pytest = "^7.3.1" pytest-asyncio = "^0.21.0" toml-sort = "^0.23.0" 작성한 코드의 차이점은 db가 로컬에 있지 않고 외부에 있는 관계로def create_mongo_url(host: str = "localhost", port: int = 27017) -> str: return f"mongodb://{host}:{port}" DATABASE_NAME = os.environ.get("MONGO_DATABASE", "yorigin") HOST = os.environ.get("MONGO_HOST", "localhost") PORT = os.environ.get("MONGO_PORT", 27017) client = AsyncIOMotorClient(create_mongo_url(HOST, int(PORT)))이와 같은 코드를 추가하여 지정된 host의 mongodb와 통신할 수 있도록 한 것이 전부입니다. 확인 부탁드릴 수 있을까요?