C.W.K.
Stream
Lesson 05 of 12 · published

Notebook 테스트

~9 min · jupyter, notebooks, papermill

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Notebook 빨리 썩어

Jupyter notebook 은 ML repo 어디에나 — 탐색 분석, 학습 스크립트, 데모 플로우, 튜토리얼 페이지. Commit 순간 썩기 시작: output 오래되고, deps 이동, '내 노트북에서 그냥 됨' 상태 나이 들어.

Notebook 을 코드처럼. CI 에서 test.

도구

  • papermill — 매개변수화된 입력으로 notebook end-to-end 실행. 출력은 모든 cell 돈 새 notebook.
  • pytest --nbmake — notebook 을 pytest test 로 실행.
  • jupyter nbconvert --execute — 내장, 단순.
  • nbqa — notebook 에 ruff / black / mypy 실행.

뭘 단언

  1. Notebook 이 에러 없이 완료까지 돔.
  2. 특정 cell 이 기대 output 생산 (papermill + 작은 test 스크립트).
  3. Lint / format 깨끗 (nbqa + ruff).
  4. Output 은 commit 전 strip (nbstripout 또는 pre-commit hook) — diff 가 읽기 가능하게.

Code

Notebook test job·yaml
  notebooks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v3
      - run: uv sync --all-extras --dev
      - name: Lint notebooks
        run: uv run nbqa ruff notebooks/
      - name: Execute notebooks
        run: |
          for nb in notebooks/*.ipynb; do
            uv run papermill "$nb" "/tmp/$(basename $nb)" --no-progress-bar
          done

External links

Exercise

Notebook 있는 repo 에 nbstripout 를 pre-commit hook 으로 추가. 각 notebook 을 papermill 로 end-to-end 실행하는 CI job 추가. Notebook 이 버전 bump 에 걸쳐 green 유지 되는 거 봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.