Skip to Content
Pythonによるテスト駆動開発, 3rd Edition
book

Pythonによるテスト駆動開発, 3rd Edition

by Harry Percival
October 2025
Intermediate to advanced
712 pages
9h 46m
Japanese
O'Reilly Media, Inc.
Content preview from Pythonによるテスト駆動開発, 3rd Edition

第18章 新しいコードのデプロイ

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

我々の素晴らしい新しい検証コードを本番サーバにデプロイする時が来た。これで自動デプロイスクリプトが実際に動くのを二度目に目にする機会となる。この機会に小さなデプロイチェックリストを作成しよう。

この時点で、アンドルー・ゴッドウィンと Django チーム全員に心から感謝したい。 初版では、移行について 長いセクションを割いて説明していた。 Django 1.7 以降、移行は「ただ機能する」ようになったため、そのセクションを完全に削除することができた。 確かに、これは 10 年近くも前の話だが、 それでも、オープンソースソフトウェアは贈り物だ。 私たちは、まったく無料で、このような素晴らしいものを手に入れることができる。 時々、感謝の気持ちを込めて、少し立ち止まって考える価値がある。

デプロイチェックリスト

デプロイ前のタスクを簡単にチェックリストにしてみよう:

  1. 念のため、全ての単体テストと機能テスト(FT)を通常通り実行する。

  2. Dockerイメージを再構築し、ローカルマシンのDocker環境でテストを実行する。

  3. ステージング環境にデプロイし、ステージング環境で FT を実行する。

  4. これで本番環境にデプロイできる。

ヒント

このようなデプロイチェックリストは一時的な措置であるべきだ。 手動で数回実行したら、 次の自動化ステップへ進むべきだ: CI/CD(継続的インテグレーション/継続的デプロイメント)パイプラインを用いた本番環境への直接デプロイだ。第25章で触れる。

ローカル環境での完全なテスト実行

もちろん、テスト用ヤギの監視のもと、 常にテストは実行している! だが念のため:

$ cd src && python manage.py test
[...]

Ran 37 tests in 15.222s

OK

Docker での簡易テスト実行

本番環境への次のステップは、Docker での実行だ。これが、わざわざアプリをコンテナ化した主な理由の一つだ: 自分のマシン上で、本番環境を可能な限り忠実に再現するためだ。

ではDockerイメージを再構築し、ローカルDockerコンテナを起動しよう:

$ *docker build -t superlists . && docker run \ -p 8888:8888 \ --mount type=bind,source="$PWD/src/db.sqlite3",target=/src/db.sqlite3 \ -e DJANGO_SECRET_KEY=sekrit \ -e DJANGO_ALLOWED_HOST=localhost \ -e DJANGO_DB_PATH=/home/nonroot/db.sqlite3 \ -it superlists => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 371B 0.0s => [internal] load metadata for docker.io/library/python:3.14-slim 1.4s [...] => => naming to docker.io/library/superlists 0.0s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

イーサリアムをマスターする, 2nd Edition

イーサリアムをマスターする, 2nd Edition

Carlo Parisi, Alessandro Mazza, Niccolo Pozzolini, Gavin Wood, Andreas M. Antonopoulos
Excel用Python

Excel用Python

Felix Zumstein

Publisher Resources

ISBN: 0642572274771