Skip to main content

pytest-suite

Write or extend the backend test suite following this project's conventions. Use when adding tests for a new service/route/repository, when coverage is missing, or when asked to test a feature. Knows the mocked-session + httpx AsyncClient setup so tests run with no database.

설치로 이동

소스 정보

저장소
vstorm-co/full-stack-ai-agent-template
최근 소스 활동
2026년 6월 22일 14:41
감지된 SKILL.md 언어
영어
스타
1,898
포크
375

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
pytest-suite
description
Write or extend the backend test suite following this project's conventions. Use when adding tests for a new service/route/repository, when coverage is missing, or when asked to test a feature. Knows the mocked-session + httpx AsyncClient setup so tests run with no database.
# Backend Tests (pytest + anyio) Tests live in `backend/tests/`, mirror the source layout (`app/services/user.py` → `tests/services/test_user.py`), and run with **no real database** — `conftest.py` overrides `get_db_session` with an `AsyncMock` via FastAPI `dependency_overrides`. ## Key fixtures (`tests/conftest.py`) - `client` — `httpx.AsyncClient` over `ASGITransport(app=app)` (use this, **not** Starlette `TestClient`) - `mock_db_session` — `AsyncMock` standing in for `AsyncSession` - `mock_redis` (when Redis is enabled), `api_key_headers` (when API keys are enabled) ## Patterns **Async tests** use anyio, not `@pytest.mark.asyncio`: ```python import pytest pytestmark = pytest.mark.anyio # at module top, or mark per-test ``` **Service test** — stub what the repo/session returns, assert behavior + exceptions: ```python async def test_get_user_not_found_raises(monkeypatch, mock_db_session): service = UserService(mock_db_session) monkeypatch.setattr(user_repo, "get_by_id", AsyncMock(return_value=None)) with pytest.raises(NotFoundError): await service.get_by_id(UUID("00000000-0000-0000-0000-000000000000")) ``` **API test** — drive the route through `client`, override auth deps with a mock user: ```python async def test_create_user_returns_201(client: AsyncClient): app.dependency_overrides[get_current_user] = lambda: mock_user resp = await client.post("/api/v1/users", json={"email": "a@b.com", "password": "secret123"}) assert resp.status_code == 201 ``` ## Naming & rules - `test_<action>_<scenario>_<expected_result>` (e.g. `test_create_user_with_duplicate_email_raises_already_exists_error`) - One behavior per test; plain `assert` (pytest rewrites it) - Use factory fixtures for data, not raw dicts; each test independent - Clear `app.dependency_overrides` after the test (the `client` fixture already does this for the DB/Redis overrides) ## Run ```bash cd backend && uv run pytest # all uv run pytest tests/services/test_user.py -v uv run pytest --cov=app # coverage ``` After writing tests, run `uv run ruff check . --fix && uv run ruff format .` and confirm `uv run pytest` is green.
GitHub에서 보기