不安定なテスト(flaky test)をくり返し実行で特定

Flaky test hunter: rerun tests N times and find the unstable ones

テストコマンドを指定回数くり返し実行し、毎回の成否・所要時間・出力を記録して、成功と失敗の両方があったテストを失敗率つきで報告します。原因の調べ方と直し方も案内します。

ClaudeHermes AgentCodexCursorMIT(改変・再配布・商用利用可)Python

できること

「たまに落ちるテスト」を推測ではなく記録で特定します。

  • 指定したテストコマンドを N 回実行し、各回の終了コード・所要時間・出力(ログファイル)を保存
  • pytest・jest・vitest・mocha・go test・unittest・cargo test・TAP の結果行をテストごとに集計
  • 成功と失敗の両方があったテストを「不安定」、毎回失敗するテストを「常に失敗」として分けて報告(失敗した回の番号と失敗率つき)
  • 所要時間の最小・中央値・最大を出し、タイムアウトした回も記録
  • 原因の候補(実行順序・時刻・乱数・ネットワーク・非同期処理・並列実行など)と確かめ方を資料として同梱

使い方

python scripts/flaky_hunter.py --runs 20 -- pytest -rA -q tests/test_api.py
python scripts/flaky_hunter.py --runs 20 --timeout 120 --shell "npx jest --verbose --runInBand"

結果は flaky-report/report.md・results.json・logs/ に保存されます。エージェントが失敗した回のログとテストコードを読み、原因と修正案を報告します。

必要な環境

  • Python 3(標準ライブラリのみ)
  • 対象プロジェクトのテストを実行できる環境

注意点

  • 指定したコマンドを N 回そのまま実行します。データベースや外部サービスに触れるテストは、テスト用の環境で実行してください。
  • テストごとの集計には、1 テスト 1 行を出す詳細表示(-rA・--verbose・-v など)が必要です。認識できない形式でも、実行単位の成否とログは残ります。
  • N 回失敗しなかったことは「不安定ではない」証明にはなりません。
English description

Reruns a test command N times, records pass/fail, timings and output of every run, and reports tests that both passed and failed, with failure rates and likely causes.

What it does

Finds flaky tests from recorded evidence instead of guesses.

  • Runs the given test command N times and saves each run's exit code, duration and output (log files)
  • Aggregates per-test results from pytest, jest, vitest, mocha, go test, unittest, cargo test and TAP output
  • Reports tests that both passed and failed as flaky, and tests that failed every time as always failing, with failing run numbers and failure rates
  • Shows min, median and max run time and records timed-out runs
  • Includes a reference of common causes (order dependence, time, randomness, network, async, parallelism) and how to confirm them

How to use

python scripts/flaky_hunter.py --runs 20 -- pytest -rA -q tests/test_api.py
python scripts/flaky_hunter.py --runs 20 --timeout 120 --shell "npx jest --verbose --runInBand"

Results go to flaky-report/report.md, results.json and logs/. The agent reads the failing logs and the test code, then reports likely causes and fixes.

Requirements

  • Python 3 (standard library only)
  • An environment that can run the project's tests

Caveats

  • The command is executed N times as given; run suites that touch databases or external services in a test environment.
  • Per-test results need a reporter that prints one line per test (-rA, --verbose, -v). Unrecognized output still gives run-level results and logs.
  • No failure in N runs does not prove a test is not flaky.

インストール方法

  1. ダウンロードしたZIPを展開します(中に flaky-test-hunter/ フォルダと SKILL.md があります)。
  2. フォルダごと、使うエージェントのスキル置き場にコピーします。
    • Claude:~/.claude/skills/(プロジェクト単位なら .claude/skills/)
    • Hermes Agent:~/.hermes/skills/
    • Codex:~/.agents/skills//Cursor:~/.cursor/skills/
    • Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
  3. エージェントを再起動し、スキル一覧に表示されることを確認します。

Windows・Mac 別、エージェント別のインストール手順

出品者

AI Skill Market 公式

出品スキル 44 件

出品者のプロフィールとスキル一覧