해결된 질문
작성
·
125
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 ===============
아래와 같이 라이브러리들을 설정했는데요 혹시 문제되는 버전이 있을까요??
전체 다 다시 설치해봐도 안되어서 문의 드립니다.