スキル一覧に戻る
Jawad-Chaudhary

pytest-testing

by Jawad-Chaudhary

The Evolution of Todo: A spec-driven, AI-native journey from a Python CLI to a Cloud-Native, Event-Driven AI Chatbot deployed on Kubernetes. Built with Claude Code, Spec-Kit Plus, Next.js, FastAPI, and Dapr.

0🍴 0📅 2026年1月22日
GitHubで見るManusで実行

SKILL.md


name: pytest-testing description: Async testing with pytest, pytest-asyncio, httpx, fixtures, coverage reports, and test-first development. Use when writing tests, test fixtures, or measuring coverage.

Pytest Async Testing

Configuration (pytest.ini)

[pytest]
asyncio_mode = auto
testpaths = tests
addopts = --cov=. --cov-report=html --cov-report=term-missing --cov-fail-under=80

Fixtures (conftest.py)

import pytest
import pytest_asyncio
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from httpx import AsyncClient

@pytest_asyncio.fixture
async def db_session():
    engine = create_async_engine("sqlite+aiosqlite:///:memory:")
    async with engine.begin() as conn:
        await conn.run_sync(SQLModel.metadata.create_all)
    async_session = sessionmaker(engine, class_=AsyncSession)
    async with async_session() as session:
        yield session
    await engine.dispose()

@pytest_asyncio.fixture
async def client():
    async with AsyncClient(app=app, base_url="http://test") as ac:
        yield ac

@pytest.fixture
def auth_token():
    return generate_test_token("test_user")

Async Tests

@pytest.mark.asyncio
async def test_endpoint(client, auth_token):
    response = await client.post(
        "/api/user123/chat",
        json={"message": "Add task"},
        headers={"Authorization": f"Bearer {auth_token}"}
    )
    assert response.status_code == 200
    data = response.json()
    assert "conversation_id" in data

Coverage

pytest --cov=. --cov-report=html  # Generate HTML report
pytest --cov=. --cov-report=term-missing  # Show missing lines
pytest --cov-fail-under=80  # Fail if below 80%

Test-First Pattern

  1. Write test defining expected behavior
  2. Run test (should fail)
  3. Implement code to pass test
  4. Refactor while keeping tests green

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です