pytest + httpx TestClient 인프라 도입 (TDD 정착) #18

Closed
opened 2026-04-22 02:22:49 +09:00 by xhh · 0 comments
Owner

Sprint 2 본격 기능 추가 전, 회귀 방지 기반을 먼저 놓는다. 이후 모든 신규 엔드포인트는 테스트 동반 작성 (TDD) 을 관례화.

작업 범위

디렉토리 구조

  • tests/
    • conftest.py — 공용 fixture
    • api/ — 엔드포인트 테스트 (test_watchlist.py, test_prices.py, ...)
    • collectors/ — 수집기 유닛 테스트 (OpenBB fallback 등)
    • storage/ — 모델 제약 테스트 (UniqueConstraint 등)

conftest 주요 fixture

  • test_db: SQLite in-memory DB + create_all (세션별 격리)
  • client: FastAPI TestClient + 위 DB 바인딩 + API_AUTH_DISABLED=1 주입
  • seeded_watchlist: AMD/TSLA/FCX 시드된 상태로 시작

의존성

  • httpx 는 dev 그룹에 이미 있음
  • pytest-asyncio 추가 (FastAPI async 라우터 대비)

실행

  • uv run pytest 가 표준 명령
  • 병렬화는 나중에 (pytest-xdist)

CI 연동

  • .forgejo/workflows/test.yml 신설
  • 트리거: PR open/synchronize. tag push 의 deploy 전에도 통과 필수로 게이트 거는 방향 검토
  • Runner 이미지에 pytest 없음 → uv run pytest 로 격리 실행 (uv sync 재사용)

완료 기준

  1. uv run pytest 가 로컬에서 돌아가고 최소 하나의 smoke test (GET /api/health 200) 통과
  2. PR 에서 자동 실행되어 Forgejo Actions 에 체크 표시
  3. README 에 "테스트 실행" 절 추가 (간단 1~2줄)

의존 없음. 다른 Sprint 2 이슈보다 먼저 완료 권고.

Sprint 2 본격 기능 추가 전, 회귀 방지 기반을 먼저 놓는다. 이후 모든 신규 엔드포인트는 테스트 동반 작성 (TDD) 을 관례화. ## 작업 범위 ### 디렉토리 구조 - `tests/` - `conftest.py` — 공용 fixture - `api/` — 엔드포인트 테스트 (`test_watchlist.py`, `test_prices.py`, ...) - `collectors/` — 수집기 유닛 테스트 (OpenBB fallback 등) - `storage/` — 모델 제약 테스트 (UniqueConstraint 등) ### conftest 주요 fixture - `test_db`: SQLite in-memory DB + create_all (세션별 격리) - `client`: FastAPI TestClient + 위 DB 바인딩 + API_AUTH_DISABLED=1 주입 - `seeded_watchlist`: AMD/TSLA/FCX 시드된 상태로 시작 ### 의존성 - `httpx` 는 dev 그룹에 이미 있음 - `pytest-asyncio` 추가 (FastAPI async 라우터 대비) ### 실행 - `uv run pytest` 가 표준 명령 - 병렬화는 나중에 (pytest-xdist) ### CI 연동 - `.forgejo/workflows/` 에 `test.yml` 신설 - 트리거: PR open/synchronize. tag push 의 deploy 전에도 통과 필수로 게이트 거는 방향 검토 - Runner 이미지에 pytest 없음 → `uv run pytest` 로 격리 실행 (uv sync 재사용) ## 완료 기준 1. `uv run pytest` 가 로컬에서 돌아가고 최소 하나의 smoke test (GET /api/health 200) 통과 2. PR 에서 자동 실행되어 Forgejo Actions 에 체크 표시 3. README 에 "테스트 실행" 절 추가 (간단 1~2줄) ## 의존 없음. 다른 Sprint 2 이슈보다 먼저 완료 권고.
xhh closed this issue 2026-04-22 02:35:35 +09:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
xhh/financial-data-platform#18
No description provided.