Help us understand the problem. What is going on with this article?

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

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

動作イメージ

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

参考

danpe919
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした