feat: pytest + httpx TestClient 인프라 도입 (#18) #23

Merged
xhh merged 1 commit from issue-18-pytest-infra into main 2026-04-22 02:35:35 +09:00
Owner

요약

Quality Foundation 마일스톤의 첫 이슈. Sprint 2 본격 기능 전에 TDD 기반을 놓는다.

구성

  • tests/ 디렉토리 분리: api / collectors / storage
  • conftest.py: SQLite in-memory + StaticPool, FastAPI dependency_overrides(get_database, get_session), API_AUTH_DISABLED 자동. 실 DB 는 절대 건드리지 않음.
  • tests/api/test_health.py: smoke test 3건 (/api/health, /api/version, /openapi.json)
  • pyproject.toml [tool.pytest.ini_options]: testpaths, pythonpath=src, asyncio_mode=auto, filterwarnings, strict flags
  • .forgejo/workflows/test.yml: PR 트리거로 자동 pytest. Runner 라벨 nas 재사용.
  • README: 테스트 실행 가이드 + TDD 관례 명시

검증

로컬 uv run pytest → 3 passed (4.29s). 네트워크/외부 I/O 없음.

다음

  • #19 (deps.get_session 회귀 테스트) 가 이 인프라 위에서 작성됨
  • Sprint 2 의 #2, #4, #21 구현 시 테스트 동반 작성 권고

Closes #18

## 요약 Quality Foundation 마일스톤의 첫 이슈. Sprint 2 본격 기능 전에 TDD 기반을 놓는다. ## 구성 - **tests/** 디렉토리 분리: api / collectors / storage - **conftest.py**: SQLite in-memory + StaticPool, FastAPI dependency_overrides(get_database, get_session), API_AUTH_DISABLED 자동. **실 DB 는 절대 건드리지 않음**. - **tests/api/test_health.py**: smoke test 3건 (/api/health, /api/version, /openapi.json) - **pyproject.toml [tool.pytest.ini_options]**: testpaths, pythonpath=src, asyncio_mode=auto, filterwarnings, strict flags - **.forgejo/workflows/test.yml**: PR 트리거로 자동 pytest. Runner 라벨 nas 재사용. - **README**: 테스트 실행 가이드 + TDD 관례 명시 ## 검증 로컬 `uv run pytest` → 3 passed (4.29s). 네트워크/외부 I/O 없음. ## 다음 - #19 (deps.get_session 회귀 테스트) 가 이 인프라 위에서 작성됨 - Sprint 2 의 #2, #4, #21 구현 시 테스트 동반 작성 권고 Closes #18
pytest + httpx TestClient 인프라 도입 (#18)
Some checks failed
Tests (PR) / pytest (pull_request) Failing after 15s
546b402ffa
Sprint 2 본격 기능 전 선행되는 TDD 기반. 이후 모든 신규 엔드포인트/수집기는 테스트 동반 작성을 관례로 한다.

## 구성

### 디렉토리
- tests/{api,collectors,storage}/  — 도메인별 분리
- tests/conftest.py                 — 공용 fixture
- tests/api/test_health.py          — smoke test (3 case)

### conftest 핵심 fixture
- test_engine: SQLite in-memory + StaticPool (스레드 공유). create_all 로 스키마 즉시 생성. 실 DB 는 절대 건드리지 않음.
- test_session_factory / test_session
- client: TestClient + FastAPI dependency_overrides 로 get_database/get_session 을 test DB 로 스위치. API_AUTH_DISABLED=1 자동 설정.

### pyproject.toml [tool.pytest.ini_options]
- testpaths=tests, pythonpath=src, asyncio_mode=auto
- addopts 에 --strict-markers --strict-config
- filterwarnings: 기본 error, DeprecationWarning 만 default (OpenBB 의 Pydantic v2 경고 다수)

### CI (.forgejo/workflows/test.yml)
- trigger: pull_request(main) + workflow_dispatch
- Runner 라벨 nas 재사용 (uv 는 curl 로 in-step 설치)
- uv sync --frozen + uv run pytest

### 의존성
- pytest-asyncio 추가 (dev)
- httpx, pytest, pytest-cov 는 기존 있음

### README
- "테스트" 절 추가: uv run pytest / --cov / PR CI 안내 + TDD 관례 명시

## 검증

로컬 uv run pytest -> 3 passed (/api/health, /api/version, /openapi.json smoke). 외부 I/O 없이 ~4초 내 완료.

Closes #18

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
xhh merged commit 368a9bfe9d into main 2026-04-22 02:35:35 +09:00
Sign in to join this conversation.
No reviewers
No milestone
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!23
No description provided.