LoginSignup
2
1

More than 3 years have passed since last update.

ファイルを保存時に自動でテストを実行する

Posted at

テスト駆動開発において、「ファイルを更新」 -> 「コンソールでテストコマンドを実行」 というプロセスが面倒でした。
そこで、このプロセスを自動化する方法を記載します。

動作イメージ

test.gif

環境

  • Ubuntu 18.04

準備

sudo apt install inotify-tools

コード

以下のスクリプトを作成し、プロジェクトのルートに配置します。

autorun.sh
#!/usr/bin/env bash

TEST_RUNNER="pytest -s tests" # 実行したいテストコマンドを指定
TARGETS="./src ./tests" # 監視したディレクトリを指定

while inotifywait -r -e modify -e create -e delete $TARGETS; do
  $TEST_RUNNER
done

実行権限も付与。

chmod +x ./autorun.sh

実行

./autorun.sh

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1