PHpullh

PYTHON · 테스트

CI/CD 테스트

GitHub Actions 등 CI/CD 파이프라인에서 테스트를 자동화하는 설정입니다.

테스트중급CI/CDGitHub Actions자동화파이프라인

핵심 설명

GitHub Actions 등 CI/CD 파이프라인에서 테스트를 자동화하는 설정입니다.

Python code

# .github/workflows/test.yml 내용
ci_config = """
name: Python Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12"]

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        pip install -e ".[dev]"
    - name: Lint
      run: ruff check src/
    - name: Type check
      run: mypy src/
    - name: Test
      run: pytest --cov=src --cov-report=xml -v
    - name: Upload coverage
      uses: codecov/codecov-action@v3
"""
print(ci_config)

# pyproject.toml 테스트 설정
pyproject_testing = """
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-v --tb=short --strict-markers"
markers = [
    "slow: 느린 테스트",
    "integration: 통합 테스트",
]

[tool.coverage.run]
source = ["src"]
omit = ["*/tests/*"]

[tool.coverage.report]
fail_under = 80
show_missing = true
"""
print(pyproject_testing)

학습 팁

Python 버전 매트릭스로 여러 버전에서 동시에 테스트하면 호환성 문제를 조기에 발견합니다.

주의할 점

CI에서 pip install -r requirements.txt만 하면 dev 의존성(pytest 등)이 설치되지 않습니다. [dev] 그룹을 포함하세요.

자주 묻는 질문

CI/CD 테스트란 무엇인가요?

GitHub Actions 등 CI/CD 파이프라인에서 테스트를 자동화하는 설정입니다.

CI/CD 테스트 학습 시 주의할 점은 무엇인가요?

CI에서 pip install -r requirements.txt 만 하면 dev 의존성(pytest 등)이 설치되지 않습니다. [dev] 그룹을 포함하세요.