detox で tox テストを並列実行しよう

複数の Python バージョンでテストを実行するツールに tox があります。

tox ツールそのものがとても便利なのですが、この tox テストを並列実行してくれるツールがリリースされました。

既に tox を使っている環境であれば、detox をインストールするだけで良いです。

$ pip install detox

使い方は tox と全く同じで特別な設定は不要です。tox コマンドを実行する代わりに detox コマンドを実行します。試しに実行してみましょう。

(test)$ detox 
py26 create: /Users/t2y/work/repo/littlehttpserver/.tox/py26
GLOB sdist-make: /Users/t2y/work/repo/littlehttpserver/setup.py
py27 create: /Users/t2y/work/repo/littlehttpserver/.tox/py27
py32 create: /Users/t2y/work/repo/littlehttpserver/.tox/py32
py26 installdeps: :pypi:pytest, :pypi:pep8 
py27 installdeps: :pypi:pytest, :pypi:pep8
py32 installdeps: :pypi:pytest, :pypi:pep8
installdeps py26- py27/ py32-         

この例では、Python 2.6, 2.7, 3.2 の tox テストが並列実行され、依存パッケージのインストール中です。

最終的な実行結果です。

(test)$ detox 
GLOB sdist-make: /Users/t2y/work/repo/littlehttpserver/setup.py
py27 sdist-reinst: /Users/t2y/work/repo/littlehttpserver/.tox/dist/LittleHTTPServer-0.1.2.zip
py32 sdist-reinst: /Users/t2y/work/repo/littlehttpserver/.tox/dist/LittleHTTPServer-0.1.2.zip
py26 sdist-reinst: /Users/t2y/work/repo/littlehttpserver/.tox/dist/LittleHTTPServer-0.1.2.zip
py26 runtests: commands[0]    
py27 runtests: commands[0]               
py32 runtests: commands[0]               
_______________________________ summary ________________________________
  py26: commands succeeded
  py27: commands succeeded
  py32: commands succeeded
  congratulations :)

1つの tox 環境でテストが通ったときに素早く他の環境でも実行したい、ちょっとした修正を行ったときに他の環境でも一応テストしてみたい、といった用途にとても便利です。何よりも CPU パワーが有り余ってるマシンで並列処理を実行するのは気持ち良いです。

detox は、並列処理に eventlet を使っていて、detox のソース自体も百数十行というシンプルなものです。eventlet の GreePool から greenthread でプロセスを実行しているようです。私は eventlet を使っているソースを初めて見かけたので興味深かったです (^ ^;;