본문으로 건너뛰기

[pydantic-ai] 테스트 스위트에서 불필요한 asyncio.sleep 제거

PR 링크: pydantic/pydantic-ai#3868 상태: Merged | 변경: +21 / -76

들어가며

테스트 코드에 남아있는 asyncio.sleep() 호출과 불필요한 @pytest.mark.vcr() 마커는 테스트 스위트 전체의 실행 시간을 느리게 합니다. 이 PR은 Google 모델 파일 검색 테스트와 OpenAI Responses 모델 테스트에서 이런 불필요한 대기와 마커를 일괄 정리합니다.

핵심 코드 분석

Google 모델 파일 검색 테스트에서 sleep 제거

Before:

async def test_google_model_file_search_tool(allow_model_requests, google_provider):
    async with google_provider.client.aio.caches.create(...) as store:
        async with store.upload(...) as upload:
            await upload.upload_file(...)

        await asyncio.sleep(3)  # 불필요한 3초 대기

        m = GoogleModel('gemini-2.5-pro', provider=google_provider)

After:

async def test_google_model_file_search_tool(allow_model_requests, google_provider):
    async with google_provider.client.aio.caches.create(...) as store:
        async with store.upload(...) as upload:
            await upload.upload_file(...)

        m = GoogleModel('gemini-2.5-pro', provider=google_provider)

파일 업로드 후 3초 대기가 제거되었습니다. VCR cassette 기반 테스트에서는 실제 API 호출이 발생하지 않으므로 대기가 무의미합니다.

OpenAI Responses 테스트에서 VCR 마커 및 정리

-@pytest.mark.vcr()
 async def test_image_as_binary_content_tool_response(...):

-@pytest.mark.vcr()
 async def test_reasoning_model_with_temperature(...):

-@pytest.mark.vcr()
 async def test_gpt5_pro(...):

약 15개의 테스트에서 @pytest.mark.vcr() 마커가 제거되었습니다. 또한 파일 관련 테스트가 tmp_path fixture를 사용하도록 개선되었습니다:

# Before
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
    f.write('Paris is the capital of France.')
    test_file_path = f.name

# After
test_file_path = tmp_path / 'file.txt'
test_file_path.touch()
test_file_path.write_text('Paris is the capital of France.')

왜 이게 좋은가

개별 asyncio.sleep(3)은 작아 보이지만, CI에서 수백 개의 테스트가 실행될 때 누적 효과가 큽니다. VCR(Video Cassette Recorder) 마커가 불필요한 테스트에 붙어 있으면 cassette 파일 관리 오버헤드도 발생합니다. tmp_path fixture는 pytest가 자동으로 정리하므로 delete=False로 인한 임시 파일 누적도 방지됩니다. 작은 정리지만 테스트 스위트 전체의 건강성에 기여합니다.

정리

항목 내용
sleep 제거 Google 파일 검색 테스트 2곳 (각 3초)
VCR 제거 OpenAI Responses 테스트 약 15곳
tmpfile 개선 tempfile.NamedTemporaryFile -> tmp_path fixture

참고 자료

⚠️ 알림: 이 분석은 AI가 실제 코드 diff를 기반으로 작성했습니다.

댓글

관련 포스트

PR Analysis 의 다른글