해결된 질문
작성
·
87
0
안녕하세요 테스트 코드 사용 중 오류가 잡히지 않아서 문의 드립니다.
강의에서 설명해주신 것처럼 아래와 같이 코드를 작성했지만 오류가 발생합니다.
어떻게 해야 할까요?
from fastapi.testclient import TestClient
from main import app
# api들이 있는 app을 검증할 클라이언트 생성
client = TestClient(app=app)
def test_health_check():
# api 요청
response = client.get("/")
# 반환 값 검증
assert response.status_code == 200
assert response.json() == {"ping": "pong"}
아래는 오류 내용 입니다.
(fastapi_orm) C:\Users\User\Desktop\Fast_API(ORM)\code\src>pytest
============================================================================= test session starts =============================================================================
platform win32 -- Python 3.10.16, pytest-8.3.5, pluggy-1.5.0
rootdir: C:\Users\User\Desktop\Fast_API(ORM)\code\src
plugins: anyio-4.8.0
collected 0 items / 1 error
=================================================================================== ERRORS ====================================================================================
_____________________________________________________________________ ERROR collecting tests/test_main.py _____________________________________________________________________
tests\test_main.py:5: in <module>
client = TestClient(app)
..\..\..\..\anaconda3\envs\fastapi_orm\lib\site-packages\starlette\testclient.py:399: in __init__
super().__init__(
E TypeError: Client.__init__() got an unexpected keyword argument 'app'
=========================================================================== short test summary info ===========================================================================
ERROR tests/test_main.py - TypeError: Client.__init__() got an unexpected keyword argument 'app'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================== 1 error in 0.86s ===============
아래와 같이 라이브러리들을 설정했는데요 혹시 문제되는 버전이 있을까요??
전체 다 다시 설치해봐도 안되어서 문의 드립니다.
(fastapi_orm) C:\Users\User\Desktop\Fast_API(ORM)\code\src>pip list Package Version ----------------- --------- anyio 4.8.0 certifi 2025.1.31 cffi 1.17.1 click 8.1.8 colorama 0.4.6 cryptography 44.0.2 exceptiongroup 1.2.2 fastapi 0.97.0 greenlet 3.1.1 h11 0.14.0 httpcore 1.0.7 httpx 0.28.1 idna 3.10 iniconfig 2.0.0 packaging 24.2 pip 25.0 pluggy 1.5.0 pycparser 2.22 pydantic 1.10.21 PyMySQL 1.1.1 pytest 8.3.5 pytest-mock 3.14.0 setuptools 75.8.0 sniffio 1.3.1 SQLAlchemy 2.0.38 starlette 0.27.0 tomli 2.2.1 typing_extensions 4.12.2 uvicorn 0.34.0 wheel 0.45.1